forked from google/gnostic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery.go
1699 lines (1665 loc) · 60.4 KB
/
discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2020 Google LLC. 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 discovery_v1
import (
"fmt"
"regexp"
"strings"
"gopkg.in/yaml.v3"
"github.com/google/gnostic/compiler"
)
// Version returns the package name (and OpenAPI version).
func Version() string {
return "discovery_v1"
}
// NewAnnotations creates an object of type Annotations if possible, returning an error if not.
func NewAnnotations(in *yaml.Node, context *compiler.Context) (*Annotations, error) {
errors := make([]error, 0)
x := &Annotations{}
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{"required"}
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))
}
// repeated string required = 1;
v1 := compiler.MapValueForKey(m, "required")
if v1 != nil {
v, ok := compiler.SequenceNodeForNode(v1)
if ok {
x.Required = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for required: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewAny creates an object of type Any if possible, returning an error if not.
func NewAny(in *yaml.Node, context *compiler.Context) (*Any, error) {
errors := make([]error, 0)
x := &Any{}
bytes := compiler.Marshal(in)
x.Yaml = string(bytes)
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewAuth creates an object of type Auth if possible, returning an error if not.
func NewAuth(in *yaml.Node, context *compiler.Context) (*Auth, error) {
errors := make([]error, 0)
x := &Auth{}
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{"oauth2"}
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))
}
// Oauth2 oauth2 = 1;
v1 := compiler.MapValueForKey(m, "oauth2")
if v1 != nil {
var err error
x.Oauth2, err = NewOauth2(v1, compiler.NewContext("oauth2", v1, context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewDocument creates an object of type Document if possible, returning an error if not.
func NewDocument(in *yaml.Node, 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{"discoveryVersion", "kind"}
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{"auth", "basePath", "baseUrl", "batchPath", "canonicalName", "description", "discoveryVersion", "documentationLink", "etag", "features", "fullyEncodeReservedExpansion", "icons", "id", "kind", "labels", "methods", "mtlsRootUrl", "name", "ownerDomain", "ownerName", "packagePath", "parameters", "protocol", "resources", "revision", "rootUrl", "schemas", "servicePath", "title", "version", "version_module"}
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 kind = 1;
v1 := compiler.MapValueForKey(m, "kind")
if v1 != nil {
x.Kind, ok = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for kind: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// string discovery_version = 2;
v2 := compiler.MapValueForKey(m, "discoveryVersion")
if v2 != nil {
x.DiscoveryVersion, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for discoveryVersion: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
// string id = 3;
v3 := compiler.MapValueForKey(m, "id")
if v3 != nil {
x.Id, ok = compiler.StringForScalarNode(v3)
if !ok {
message := fmt.Sprintf("has unexpected value for id: %s", compiler.Display(v3))
errors = append(errors, compiler.NewError(context, message))
}
}
// string name = 4;
v4 := compiler.MapValueForKey(m, "name")
if v4 != nil {
x.Name, ok = compiler.StringForScalarNode(v4)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(v4))
errors = append(errors, compiler.NewError(context, message))
}
}
// string version = 5;
v5 := compiler.MapValueForKey(m, "version")
if v5 != nil {
x.Version, ok = compiler.StringForScalarNode(v5)
if !ok {
message := fmt.Sprintf("has unexpected value for version: %s", compiler.Display(v5))
errors = append(errors, compiler.NewError(context, message))
}
}
// string revision = 6;
v6 := compiler.MapValueForKey(m, "revision")
if v6 != nil {
x.Revision, ok = compiler.StringForScalarNode(v6)
if !ok {
message := fmt.Sprintf("has unexpected value for revision: %s", compiler.Display(v6))
errors = append(errors, compiler.NewError(context, message))
}
}
// string title = 7;
v7 := compiler.MapValueForKey(m, "title")
if v7 != nil {
x.Title, ok = compiler.StringForScalarNode(v7)
if !ok {
message := fmt.Sprintf("has unexpected value for title: %s", compiler.Display(v7))
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 8;
v8 := compiler.MapValueForKey(m, "description")
if v8 != nil {
x.Description, ok = compiler.StringForScalarNode(v8)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %s", compiler.Display(v8))
errors = append(errors, compiler.NewError(context, message))
}
}
// Icons icons = 9;
v9 := compiler.MapValueForKey(m, "icons")
if v9 != nil {
var err error
x.Icons, err = NewIcons(v9, compiler.NewContext("icons", v9, context))
if err != nil {
errors = append(errors, err)
}
}
// string documentation_link = 10;
v10 := compiler.MapValueForKey(m, "documentationLink")
if v10 != nil {
x.DocumentationLink, ok = compiler.StringForScalarNode(v10)
if !ok {
message := fmt.Sprintf("has unexpected value for documentationLink: %s", compiler.Display(v10))
errors = append(errors, compiler.NewError(context, message))
}
}
// repeated string labels = 11;
v11 := compiler.MapValueForKey(m, "labels")
if v11 != nil {
v, ok := compiler.SequenceNodeForNode(v11)
if ok {
x.Labels = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for labels: %s", compiler.Display(v11))
errors = append(errors, compiler.NewError(context, message))
}
}
// string protocol = 12;
v12 := compiler.MapValueForKey(m, "protocol")
if v12 != nil {
x.Protocol, ok = compiler.StringForScalarNode(v12)
if !ok {
message := fmt.Sprintf("has unexpected value for protocol: %s", compiler.Display(v12))
errors = append(errors, compiler.NewError(context, message))
}
}
// string base_url = 13;
v13 := compiler.MapValueForKey(m, "baseUrl")
if v13 != nil {
x.BaseUrl, ok = compiler.StringForScalarNode(v13)
if !ok {
message := fmt.Sprintf("has unexpected value for baseUrl: %s", compiler.Display(v13))
errors = append(errors, compiler.NewError(context, message))
}
}
// string base_path = 14;
v14 := compiler.MapValueForKey(m, "basePath")
if v14 != nil {
x.BasePath, ok = compiler.StringForScalarNode(v14)
if !ok {
message := fmt.Sprintf("has unexpected value for basePath: %s", compiler.Display(v14))
errors = append(errors, compiler.NewError(context, message))
}
}
// string root_url = 15;
v15 := compiler.MapValueForKey(m, "rootUrl")
if v15 != nil {
x.RootUrl, ok = compiler.StringForScalarNode(v15)
if !ok {
message := fmt.Sprintf("has unexpected value for rootUrl: %s", compiler.Display(v15))
errors = append(errors, compiler.NewError(context, message))
}
}
// string service_path = 16;
v16 := compiler.MapValueForKey(m, "servicePath")
if v16 != nil {
x.ServicePath, ok = compiler.StringForScalarNode(v16)
if !ok {
message := fmt.Sprintf("has unexpected value for servicePath: %s", compiler.Display(v16))
errors = append(errors, compiler.NewError(context, message))
}
}
// string batch_path = 17;
v17 := compiler.MapValueForKey(m, "batchPath")
if v17 != nil {
x.BatchPath, ok = compiler.StringForScalarNode(v17)
if !ok {
message := fmt.Sprintf("has unexpected value for batchPath: %s", compiler.Display(v17))
errors = append(errors, compiler.NewError(context, message))
}
}
// Parameters parameters = 18;
v18 := compiler.MapValueForKey(m, "parameters")
if v18 != nil {
var err error
x.Parameters, err = NewParameters(v18, compiler.NewContext("parameters", v18, context))
if err != nil {
errors = append(errors, err)
}
}
// Auth auth = 19;
v19 := compiler.MapValueForKey(m, "auth")
if v19 != nil {
var err error
x.Auth, err = NewAuth(v19, compiler.NewContext("auth", v19, context))
if err != nil {
errors = append(errors, err)
}
}
// repeated string features = 20;
v20 := compiler.MapValueForKey(m, "features")
if v20 != nil {
v, ok := compiler.SequenceNodeForNode(v20)
if ok {
x.Features = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for features: %s", compiler.Display(v20))
errors = append(errors, compiler.NewError(context, message))
}
}
// Schemas schemas = 21;
v21 := compiler.MapValueForKey(m, "schemas")
if v21 != nil {
var err error
x.Schemas, err = NewSchemas(v21, compiler.NewContext("schemas", v21, context))
if err != nil {
errors = append(errors, err)
}
}
// Methods methods = 22;
v22 := compiler.MapValueForKey(m, "methods")
if v22 != nil {
var err error
x.Methods, err = NewMethods(v22, compiler.NewContext("methods", v22, context))
if err != nil {
errors = append(errors, err)
}
}
// Resources resources = 23;
v23 := compiler.MapValueForKey(m, "resources")
if v23 != nil {
var err error
x.Resources, err = NewResources(v23, compiler.NewContext("resources", v23, context))
if err != nil {
errors = append(errors, err)
}
}
// string etag = 24;
v24 := compiler.MapValueForKey(m, "etag")
if v24 != nil {
x.Etag, ok = compiler.StringForScalarNode(v24)
if !ok {
message := fmt.Sprintf("has unexpected value for etag: %s", compiler.Display(v24))
errors = append(errors, compiler.NewError(context, message))
}
}
// string owner_domain = 25;
v25 := compiler.MapValueForKey(m, "ownerDomain")
if v25 != nil {
x.OwnerDomain, ok = compiler.StringForScalarNode(v25)
if !ok {
message := fmt.Sprintf("has unexpected value for ownerDomain: %s", compiler.Display(v25))
errors = append(errors, compiler.NewError(context, message))
}
}
// string owner_name = 26;
v26 := compiler.MapValueForKey(m, "ownerName")
if v26 != nil {
x.OwnerName, ok = compiler.StringForScalarNode(v26)
if !ok {
message := fmt.Sprintf("has unexpected value for ownerName: %s", compiler.Display(v26))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool version_module = 27;
v27 := compiler.MapValueForKey(m, "version_module")
if v27 != nil {
x.VersionModule, ok = compiler.BoolForScalarNode(v27)
if !ok {
message := fmt.Sprintf("has unexpected value for version_module: %s", compiler.Display(v27))
errors = append(errors, compiler.NewError(context, message))
}
}
// string canonical_name = 28;
v28 := compiler.MapValueForKey(m, "canonicalName")
if v28 != nil {
x.CanonicalName, ok = compiler.StringForScalarNode(v28)
if !ok {
message := fmt.Sprintf("has unexpected value for canonicalName: %s", compiler.Display(v28))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool fully_encode_reserved_expansion = 29;
v29 := compiler.MapValueForKey(m, "fullyEncodeReservedExpansion")
if v29 != nil {
x.FullyEncodeReservedExpansion, ok = compiler.BoolForScalarNode(v29)
if !ok {
message := fmt.Sprintf("has unexpected value for fullyEncodeReservedExpansion: %s", compiler.Display(v29))
errors = append(errors, compiler.NewError(context, message))
}
}
// string package_path = 30;
v30 := compiler.MapValueForKey(m, "packagePath")
if v30 != nil {
x.PackagePath, ok = compiler.StringForScalarNode(v30)
if !ok {
message := fmt.Sprintf("has unexpected value for packagePath: %s", compiler.Display(v30))
errors = append(errors, compiler.NewError(context, message))
}
}
// string mtls_root_url = 31;
v31 := compiler.MapValueForKey(m, "mtlsRootUrl")
if v31 != nil {
x.MtlsRootUrl, ok = compiler.StringForScalarNode(v31)
if !ok {
message := fmt.Sprintf("has unexpected value for mtlsRootUrl: %s", compiler.Display(v31))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewIcons creates an object of type Icons if possible, returning an error if not.
func NewIcons(in *yaml.Node, context *compiler.Context) (*Icons, error) {
errors := make([]error, 0)
x := &Icons{}
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{"x16", "x32"}
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{"x16", "x32"}
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 x16 = 1;
v1 := compiler.MapValueForKey(m, "x16")
if v1 != nil {
x.X16, ok = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for x16: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// string x32 = 2;
v2 := compiler.MapValueForKey(m, "x32")
if v2 != nil {
x.X32, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for x32: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewMediaUpload creates an object of type MediaUpload if possible, returning an error if not.
func NewMediaUpload(in *yaml.Node, context *compiler.Context) (*MediaUpload, error) {
errors := make([]error, 0)
x := &MediaUpload{}
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{"accept", "maxSize", "protocols", "supportsSubscription"}
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))
}
// repeated string accept = 1;
v1 := compiler.MapValueForKey(m, "accept")
if v1 != nil {
v, ok := compiler.SequenceNodeForNode(v1)
if ok {
x.Accept = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for accept: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// string max_size = 2;
v2 := compiler.MapValueForKey(m, "maxSize")
if v2 != nil {
x.MaxSize, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for maxSize: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
// Protocols protocols = 3;
v3 := compiler.MapValueForKey(m, "protocols")
if v3 != nil {
var err error
x.Protocols, err = NewProtocols(v3, compiler.NewContext("protocols", v3, context))
if err != nil {
errors = append(errors, err)
}
}
// bool supports_subscription = 4;
v4 := compiler.MapValueForKey(m, "supportsSubscription")
if v4 != nil {
x.SupportsSubscription, ok = compiler.BoolForScalarNode(v4)
if !ok {
message := fmt.Sprintf("has unexpected value for supportsSubscription: %s", compiler.Display(v4))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewMethod creates an object of type Method if possible, returning an error if not.
func NewMethod(in *yaml.Node, context *compiler.Context) (*Method, error) {
errors := make([]error, 0)
x := &Method{}
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{"description", "etagRequired", "flatPath", "httpMethod", "id", "mediaUpload", "parameterOrder", "parameters", "path", "request", "response", "scopes", "streamingType", "supportsMediaDownload", "supportsMediaUpload", "supportsSubscription", "useMediaDownloadService"}
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 id = 1;
v1 := compiler.MapValueForKey(m, "id")
if v1 != nil {
x.Id, ok = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for id: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// string path = 2;
v2 := compiler.MapValueForKey(m, "path")
if v2 != nil {
x.Path, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for path: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
// string http_method = 3;
v3 := compiler.MapValueForKey(m, "httpMethod")
if v3 != nil {
x.HttpMethod, ok = compiler.StringForScalarNode(v3)
if !ok {
message := fmt.Sprintf("has unexpected value for httpMethod: %s", compiler.Display(v3))
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 4;
v4 := compiler.MapValueForKey(m, "description")
if v4 != nil {
x.Description, ok = compiler.StringForScalarNode(v4)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %s", compiler.Display(v4))
errors = append(errors, compiler.NewError(context, message))
}
}
// Parameters parameters = 5;
v5 := compiler.MapValueForKey(m, "parameters")
if v5 != nil {
var err error
x.Parameters, err = NewParameters(v5, compiler.NewContext("parameters", v5, context))
if err != nil {
errors = append(errors, err)
}
}
// repeated string parameter_order = 6;
v6 := compiler.MapValueForKey(m, "parameterOrder")
if v6 != nil {
v, ok := compiler.SequenceNodeForNode(v6)
if ok {
x.ParameterOrder = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for parameterOrder: %s", compiler.Display(v6))
errors = append(errors, compiler.NewError(context, message))
}
}
// Request request = 7;
v7 := compiler.MapValueForKey(m, "request")
if v7 != nil {
var err error
x.Request, err = NewRequest(v7, compiler.NewContext("request", v7, context))
if err != nil {
errors = append(errors, err)
}
}
// Response response = 8;
v8 := compiler.MapValueForKey(m, "response")
if v8 != nil {
var err error
x.Response, err = NewResponse(v8, compiler.NewContext("response", v8, context))
if err != nil {
errors = append(errors, err)
}
}
// repeated string scopes = 9;
v9 := compiler.MapValueForKey(m, "scopes")
if v9 != nil {
v, ok := compiler.SequenceNodeForNode(v9)
if ok {
x.Scopes = compiler.StringArrayForSequenceNode(v)
} else {
message := fmt.Sprintf("has unexpected value for scopes: %s", compiler.Display(v9))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool supports_media_download = 10;
v10 := compiler.MapValueForKey(m, "supportsMediaDownload")
if v10 != nil {
x.SupportsMediaDownload, ok = compiler.BoolForScalarNode(v10)
if !ok {
message := fmt.Sprintf("has unexpected value for supportsMediaDownload: %s", compiler.Display(v10))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool supports_media_upload = 11;
v11 := compiler.MapValueForKey(m, "supportsMediaUpload")
if v11 != nil {
x.SupportsMediaUpload, ok = compiler.BoolForScalarNode(v11)
if !ok {
message := fmt.Sprintf("has unexpected value for supportsMediaUpload: %s", compiler.Display(v11))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool use_media_download_service = 12;
v12 := compiler.MapValueForKey(m, "useMediaDownloadService")
if v12 != nil {
x.UseMediaDownloadService, ok = compiler.BoolForScalarNode(v12)
if !ok {
message := fmt.Sprintf("has unexpected value for useMediaDownloadService: %s", compiler.Display(v12))
errors = append(errors, compiler.NewError(context, message))
}
}
// MediaUpload media_upload = 13;
v13 := compiler.MapValueForKey(m, "mediaUpload")
if v13 != nil {
var err error
x.MediaUpload, err = NewMediaUpload(v13, compiler.NewContext("mediaUpload", v13, context))
if err != nil {
errors = append(errors, err)
}
}
// bool supports_subscription = 14;
v14 := compiler.MapValueForKey(m, "supportsSubscription")
if v14 != nil {
x.SupportsSubscription, ok = compiler.BoolForScalarNode(v14)
if !ok {
message := fmt.Sprintf("has unexpected value for supportsSubscription: %s", compiler.Display(v14))
errors = append(errors, compiler.NewError(context, message))
}
}
// string flat_path = 15;
v15 := compiler.MapValueForKey(m, "flatPath")
if v15 != nil {
x.FlatPath, ok = compiler.StringForScalarNode(v15)
if !ok {
message := fmt.Sprintf("has unexpected value for flatPath: %s", compiler.Display(v15))
errors = append(errors, compiler.NewError(context, message))
}
}
// bool etag_required = 16;
v16 := compiler.MapValueForKey(m, "etagRequired")
if v16 != nil {
x.EtagRequired, ok = compiler.BoolForScalarNode(v16)
if !ok {
message := fmt.Sprintf("has unexpected value for etagRequired: %s", compiler.Display(v16))
errors = append(errors, compiler.NewError(context, message))
}
}
// string streaming_type = 17;
v17 := compiler.MapValueForKey(m, "streamingType")
if v17 != nil {
x.StreamingType, ok = compiler.StringForScalarNode(v17)
if !ok {
message := fmt.Sprintf("has unexpected value for streamingType: %s", compiler.Display(v17))
errors = append(errors, compiler.NewError(context, message))
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewMethods creates an object of type Methods if possible, returning an error if not.
func NewMethods(in *yaml.Node, context *compiler.Context) (*Methods, error) {
errors := make([]error, 0)
x := &Methods{}
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 NamedMethod additional_properties = 1;
// MAP: Method
x.AdditionalProperties = make([]*NamedMethod, 0)
for i := 0; i < len(m.Content); i += 2 {
k, ok := compiler.StringForScalarNode(m.Content[i])
if ok {
v := m.Content[i+1]
pair := &NamedMethod{}
pair.Name = k
var err error
pair.Value, err = NewMethod(v, compiler.NewContext(k, v, context))
if err != nil {
errors = append(errors, err)
}
x.AdditionalProperties = append(x.AdditionalProperties, pair)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedMethod creates an object of type NamedMethod if possible, returning an error if not.
func NewNamedMethod(in *yaml.Node, context *compiler.Context) (*NamedMethod, error) {
errors := make([]error, 0)
x := &NamedMethod{}
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 = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// Method value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewMethod(v2, compiler.NewContext("value", v2, 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 *yaml.Node, 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 = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(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", v2, context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedResource creates an object of type NamedResource if possible, returning an error if not.
func NewNamedResource(in *yaml.Node, context *compiler.Context) (*NamedResource, error) {
errors := make([]error, 0)
x := &NamedResource{}
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 = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// Resource value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewResource(v2, compiler.NewContext("value", v2, 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 *yaml.Node, 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 = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(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", v2, context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewNamedScope creates an object of type NamedScope if possible, returning an error if not.
func NewNamedScope(in *yaml.Node, context *compiler.Context) (*NamedScope, error) {
errors := make([]error, 0)
x := &NamedScope{}
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 = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for name: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// Scope value = 2;
v2 := compiler.MapValueForKey(m, "value")
if v2 != nil {
var err error
x.Value, err = NewScope(v2, compiler.NewContext("value", v2, context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewOauth2 creates an object of type Oauth2 if possible, returning an error if not.
func NewOauth2(in *yaml.Node, context *compiler.Context) (*Oauth2, error) {
errors := make([]error, 0)
x := &Oauth2{}
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{"scopes"}
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))
}
// Scopes scopes = 1;
v1 := compiler.MapValueForKey(m, "scopes")
if v1 != nil {
var err error
x.Scopes, err = NewScopes(v1, compiler.NewContext("scopes", v1, context))
if err != nil {
errors = append(errors, err)
}
}
}
return x, compiler.NewErrorGroupOrNil(errors)
}
// NewParameter creates an object of type Parameter if possible, returning an error if not.
func NewParameter(in *yaml.Node, context *compiler.Context) (*Parameter, error) {
errors := make([]error, 0)
x := &Parameter{}
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", "additionalProperties", "annotations", "default", "description", "enum", "enumDescriptions", "format", "id", "items", "location", "maximum", "minimum", "pattern", "properties", "repeated", "required", "type"}
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 id = 1;
v1 := compiler.MapValueForKey(m, "id")
if v1 != nil {
x.Id, ok = compiler.StringForScalarNode(v1)
if !ok {
message := fmt.Sprintf("has unexpected value for id: %s", compiler.Display(v1))
errors = append(errors, compiler.NewError(context, message))
}
}
// string type = 2;
v2 := compiler.MapValueForKey(m, "type")
if v2 != nil {
x.Type, ok = compiler.StringForScalarNode(v2)
if !ok {
message := fmt.Sprintf("has unexpected value for type: %s", compiler.Display(v2))
errors = append(errors, compiler.NewError(context, message))
}
}
// string _ref = 3;
v3 := compiler.MapValueForKey(m, "$ref")
if v3 != nil {
x.XRef, ok = compiler.StringForScalarNode(v3)
if !ok {
message := fmt.Sprintf("has unexpected value for $ref: %s", compiler.Display(v3))
errors = append(errors, compiler.NewError(context, message))
}
}
// string description = 4;
v4 := compiler.MapValueForKey(m, "description")
if v4 != nil {
x.Description, ok = compiler.StringForScalarNode(v4)
if !ok {
message := fmt.Sprintf("has unexpected value for description: %s", compiler.Display(v4))
errors = append(errors, compiler.NewError(context, message))
}
}
// string default = 5;
v5 := compiler.MapValueForKey(m, "default")
if v5 != nil {
x.Default, ok = compiler.StringForScalarNode(v5)
if !ok {
message := fmt.Sprintf("has unexpected value for default: %s", compiler.Display(v5))
errors = append(errors, compiler.NewError(context, message))
}
}