forked from getkin/kin-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi3.txt
More file actions
2280 lines (1624 loc) · 88.1 KB
/
Copy pathopenapi3.txt
File metadata and controls
2280 lines (1624 loc) · 88.1 KB
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
package openapi3 // import "github.com/getkin/kin-openapi/openapi3"
Package openapi3 parses and writes OpenAPI 3 specification documents.
See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md
Code generated by go generate; DO NOT EDIT.
CONSTANTS
const (
ParameterInPath = "path"
ParameterInQuery = "query"
ParameterInHeader = "header"
ParameterInCookie = "cookie"
)
const (
TypeArray = "array"
TypeBoolean = "boolean"
TypeInteger = "integer"
TypeNumber = "number"
TypeObject = "object"
TypeString = "string"
TypeNull = "null"
)
const (
// FormatOfStringForUUIDOfRFC4122 is an optional predefined format for UUID v1-v5 as specified by RFC4122
FormatOfStringForUUIDOfRFC4122 = `^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$`
// FormatOfStringForEmail pattern catches only some suspiciously wrong-looking email addresses.
// Use DefineStringFormat(...) if you need something stricter.
FormatOfStringForEmail = `^[^@]+@[^@<>",\s]+$`
// FormatOfStringByte is a regexp for base64-encoded characters, for example, "U3dhZ2dlciByb2Nrcw=="
FormatOfStringByte = `(^$|^[a-zA-Z0-9+/\-_]*=*$)`
// FormatOfStringDate is a RFC3339 date format regexp, for example "2017-07-21".
FormatOfStringDate = `^[0-9]{4}-(0[0-9]|10|11|12)-([0-2][0-9]|30|31)$`
// FormatOfStringDateTime is a RFC3339 date-time format regexp, for example "2017-07-21T17:32:28Z".
FormatOfStringDateTime = `^[0-9]{4}-(0[0-9]|10|11|12)-([0-2][0-9]|30|31)T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?(Z|(\+|-)[0-9]{2}:[0-9]{2})?$`
)
const (
SerializationSimple = "simple"
SerializationLabel = "label"
SerializationMatrix = "matrix"
SerializationForm = "form"
SerializationSpaceDelimited = "spaceDelimited"
SerializationPipeDelimited = "pipeDelimited"
SerializationDeepObject = "deepObject"
)
VARIABLES
var (
IdentifierRegExp = regexp.MustCompile(`^[` + identifierChars + `]+$`)
InvalidIdentifierCharRegExp = regexp.MustCompile(`[^` + identifierChars + `]`)
)
IdentifierRegExp verifies whether Component object key matches contains just
'identifierChars', according to OpenAPI v3.x. InvalidIdentifierCharRegExp
matches all characters not contained in 'identifierChars'. However, to be
able supporting legacy OpenAPI v2.x, there is a need to customize above
pattern in order not to fail converted v2-v3 validation
var (
// SchemaErrorDetailsDisabled disables printing of details about schema errors.
SchemaErrorDetailsDisabled = false
// ErrOneOfConflict is the SchemaError Origin when data matches more than one oneOf schema
ErrOneOfConflict = errors.New("input matches more than one oneOf schemas")
// ErrSchemaInputNaN may be returned when validating a number
ErrSchemaInputNaN = errors.New("floating point NaN is not allowed")
// ErrSchemaInputInf may be returned when validating a number
ErrSchemaInputInf = errors.New("floating point Inf is not allowed")
)
var (
// SchemaStringFormats is a map of custom string format validators.
SchemaStringFormats = make(map[string]StringFormatValidator)
// SchemaNumberFormats is a map of custom number format validators.
SchemaNumberFormats = make(map[string]NumberFormatValidator)
// SchemaIntegerFormats is a map of custom integer format validators.
SchemaIntegerFormats = make(map[string]IntegerFormatValidator)
)
var DefaultReadFromURI = URIMapCache(ReadFromURIs(ReadFromHTTP(http.DefaultClient), ReadFromFile))
DefaultReadFromURI returns a caching ReadFromURIFunc which can read remote
HTTP URIs and local file URIs.
var ErrURINotSupported = errors.New("unsupported URI")
ErrURINotSupported indicates the ReadFromURIFunc does not know how to handle
a given URI.
FUNCTIONS
func BoolPtr(value bool) *bool
BoolPtr is a helper for defining OpenAPI schemas.
Deprecated: Use Ptr instead.
func DefaultRefNameResolver(doc *T, ref ComponentRef) string
DefaultRefResolver is a default implementation of refNameResolver for the
InternalizeRefs function.
The external reference is internalized to (hopefully) a unique name.
If the external reference matches (by path) to another reference in the root
document then the name of that component is used.
The transformation involves:
- Cutting the "#/components/<type>" part.
- Cutting the file extensions (.yaml/.json) from documents.
- Trimming the common directory with the root spec.
- Replace invalid characters with with underscores.
This is an injective mapping over a "reasonable" amount of the possible
openapi spec domain space but is not perfect. There might be edge cases.
func DefineIPv4Format()
DefineIPv4Format opts in ipv4 format validation on top of OAS 3 spec
func DefineIPv6Format()
DefineIPv6Format opts in ipv6 format validation on top of OAS 3 spec
func DefineIntegerFormatValidator(name string, validator IntegerFormatValidator)
DefineIntegerFormatValidator defines a custom format validator for a given
integer format.
func DefineNumberFormatValidator(name string, validator NumberFormatValidator)
DefineNumberFormatValidator defines a custom format validator for a given
number format.
func DefineStringFormat(name string, pattern string)
DefineStringFormat defines a regexp pattern for a given string format
Deprecated: Use openapi3.DefineStringFormatValidator(name,
NewRegexpFormatValidator(pattern)) instead.
func DefineStringFormatCallback(name string, callback func(string) error)
DefineStringFormatCallback defines a callback function for a given string
format
Deprecated: Use openapi3.DefineStringFormatValidator(name,
NewCallbackValidator(fn)) instead.
func DefineStringFormatValidator(name string, validator StringFormatValidator)
DefineStringFormatValidator defines a custom format validator for a given
string format.
func Float64Ptr(value float64) *float64
Float64Ptr is a helper for defining OpenAPI schemas.
Deprecated: Use Ptr instead.
func Int64Ptr(value int64) *int64
Int64Ptr is a helper for defining OpenAPI schemas.
Deprecated: Use Ptr instead.
func Ptr[T any](value T) *T
Ptr is a helper for defining OpenAPI schemas.
func ReadFromFile(loader *Loader, location *url.URL) ([]byte, error)
ReadFromFile is a ReadFromURIFunc which reads local file URIs.
func ReferencesComponentInRootDocument(doc *T, ref ComponentRef) (string, bool)
ReferencesComponentInRootDocument returns if the given component reference
references the same document or element as another component reference in
the root document's '#/components/<type>'. If it does, it returns the name
of it in the form '#/components/<type>/NameXXX'
Of course given a component from the root document will always match itself.
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#relative-references-in-urls
Example. Take the spec with directory structure:
openapi.yaml
schemas/
├─ record.yaml
├─ records.yaml
In openapi.yaml we have:
components:
schemas:
Record:
$ref: schemas/record.yaml
Case 1: records.yml references a component in the root document
$ref: ../openapi.yaml#/components/schemas/Record
This would return...
#/components/schemas/Record
Case 2: records.yml indirectly refers to the same schema as a schema the
root document's '#/components/schemas'.
$ref: ./record.yaml
This would also return...
#/components/schemas/Record
func RegisterArrayUniqueItemsChecker(fn SliceUniqueItemsChecker)
RegisterArrayUniqueItemsChecker is used to register a customized function
used to check if JSON array have unique items.
func Uint64Ptr(value uint64) *uint64
Uint64Ptr is a helper for defining OpenAPI schemas.
Deprecated: Use Ptr instead.
func ValidateIdentifier(value string) error
ValidateIdentifier returns an error if the given component name does not
match IdentifierRegExp.
func WithValidationOptions(ctx context.Context, opts ...ValidationOption) context.Context
WithValidationOptions allows adding validation options to a context object
that can be used when validating any OpenAPI type.
TYPES
type AdditionalProperties struct {
Has *bool
Schema *SchemaRef
}
func (addProps AdditionalProperties) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of AdditionalProperties.
func (addProps AdditionalProperties) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of AdditionalProperties.
func (addProps *AdditionalProperties) UnmarshalJSON(data []byte) error
UnmarshalJSON sets AdditionalProperties to a copy of data.
type Callback struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
// Has unexported fields.
}
Callback is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object
func NewCallback(opts ...NewCallbackOption) *Callback
NewCallback builds a Callback object with path items in insertion order.
func NewCallbackWithCapacity(cap int) *Callback
NewCallbackWithCapacity builds a callback object of the given capacity.
func (callback *Callback) Delete(key string)
Delete removes the entry associated with key 'key' from 'callback'.
func (callback Callback) JSONLookup(token string) (any, error)
JSONLookup implements
https://github.com/go-openapi/jsonpointer#JSONPointable
func (callback *Callback) Len() int
Len returns the amount of keys in callback excluding callback.Extensions.
func (callback *Callback) Map() (m map[string]*PathItem)
Map returns callback as a 'map'. Note: iteration on Go maps is not ordered.
func (callback *Callback) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Callback.
func (callback *Callback) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Callback.
func (callback *Callback) Set(key string, value *PathItem)
Set adds or replaces key 'key' of 'callback' with 'value'. Note: 'callback'
MUST be non-nil
func (callback *Callback) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Callback to a copy of data.
func (callback *Callback) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Callback does not comply with the OpenAPI spec.
func (callback *Callback) Value(key string) *PathItem
Value returns the callback for key or nil
type CallbackRef struct {
// Extensions only captures fields starting with 'x-' as no other fields
// are allowed by the openapi spec.
Extensions map[string]any
Origin *Origin
Ref string
Value *Callback
// Has unexported fields.
}
CallbackRef represents either a Callback or a $ref to a Callback. When
serializing and both fields are set, Ref is preferred over Value.
func (x *CallbackRef) CollectionName() string
CollectionName returns the JSON string used for a collection of these
components.
func (x *CallbackRef) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (x CallbackRef) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of CallbackRef.
func (x CallbackRef) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of CallbackRef.
func (x *CallbackRef) RefPath() *url.URL
RefPath returns the path of the $ref relative to the root document.
func (x *CallbackRef) RefString() string
RefString returns the $ref value.
func (x *CallbackRef) UnmarshalJSON(data []byte) error
UnmarshalJSON sets CallbackRef to a copy of data.
func (x *CallbackRef) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if CallbackRef does not comply with the OpenAPI
spec.
type Callbacks map[string]*CallbackRef
func (m Callbacks) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (callbacks *Callbacks) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Callbacks to a copy of data.
type ComponentRef interface {
RefString() string
RefPath() *url.URL
CollectionName() string
}
type Components struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Schemas Schemas `json:"schemas,omitempty" yaml:"schemas,omitempty"`
Parameters ParametersMap `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
RequestBodies RequestBodies `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
Responses ResponseBodies `json:"responses,omitempty" yaml:"responses,omitempty"`
SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty"`
Links Links `json:"links,omitempty" yaml:"links,omitempty"`
Callbacks Callbacks `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
}
Components is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object
func NewComponents() Components
func (components Components) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Components.
func (components Components) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Components.
func (components *Components) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Components to a copy of data.
func (components *Components) Validate(ctx context.Context, opts ...ValidationOption) (err error)
Validate returns an error if Components does not comply with the OpenAPI
spec.
type Contact struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"`
}
Contact is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contact-object
func (contact Contact) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Contact.
func (contact Contact) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Contact.
func (contact *Contact) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Contact to a copy of data.
func (contact *Contact) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Contact does not comply with the OpenAPI spec.
type Content map[string]*MediaType
Content is specified by OpenAPI/Swagger 3.0 standard.
func NewContent() Content
func NewContentWithFormDataSchema(schema *Schema) Content
func NewContentWithFormDataSchemaRef(schema *SchemaRef) Content
func NewContentWithJSONSchema(schema *Schema) Content
func NewContentWithJSONSchemaRef(schema *SchemaRef) Content
func NewContentWithSchema(schema *Schema, consumes []string) Content
func NewContentWithSchemaRef(schema *SchemaRef, consumes []string) Content
func (content Content) Get(mime string) *MediaType
func (content *Content) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Content to a copy of data.
func (content Content) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Content does not comply with the OpenAPI spec.
type Discriminator struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}
Discriminator is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
func (discriminator Discriminator) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Discriminator.
func (discriminator Discriminator) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Discriminator.
func (discriminator *Discriminator) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Discriminator to a copy of data.
func (discriminator *Discriminator) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Discriminator does not comply with the OpenAPI
spec.
type Encoding struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
Style string `json:"style,omitempty" yaml:"style,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}
Encoding is specified by OpenAPI/Swagger 3.0 standard. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encoding-object
func NewEncoding() *Encoding
func (encoding Encoding) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Encoding.
func (encoding Encoding) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Encoding.
func (encoding *Encoding) SerializationMethod() *SerializationMethod
SerializationMethod returns a serialization method of request body.
When serialization method is not defined the method returns the default
serialization method.
func (encoding *Encoding) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Encoding to a copy of data.
func (encoding *Encoding) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Encoding does not comply with the OpenAPI spec.
func (encoding *Encoding) WithHeader(name string, header *Header) *Encoding
func (encoding *Encoding) WithHeaderRef(name string, ref *HeaderRef) *Encoding
type Example struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Value any `json:"value,omitempty" yaml:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}
Example is specified by OpenAPI/Swagger 3.0 standard. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object
func NewExample(value any) *Example
func (example Example) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Example.
func (example Example) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Example.
func (example *Example) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Example to a copy of data.
func (example *Example) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Example does not comply with the OpenAPI spec.
type ExampleRef struct {
// Extensions only captures fields starting with 'x-' as no other fields
// are allowed by the openapi spec.
Extensions map[string]any
Origin *Origin
Ref string
Value *Example
// Has unexported fields.
}
ExampleRef represents either a Example or a $ref to a Example. When
serializing and both fields are set, Ref is preferred over Value.
func (x *ExampleRef) CollectionName() string
CollectionName returns the JSON string used for a collection of these
components.
func (x *ExampleRef) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (x ExampleRef) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of ExampleRef.
func (x ExampleRef) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of ExampleRef.
func (x *ExampleRef) RefPath() *url.URL
RefPath returns the path of the $ref relative to the root document.
func (x *ExampleRef) RefString() string
RefString returns the $ref value.
func (x *ExampleRef) UnmarshalJSON(data []byte) error
UnmarshalJSON sets ExampleRef to a copy of data.
func (x *ExampleRef) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if ExampleRef does not comply with the OpenAPI
spec.
type Examples map[string]*ExampleRef
func (m Examples) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (examples *Examples) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Examples to a copy of data.
type ExternalDocs struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
}
ExternalDocs is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#external-documentation-object
func (e ExternalDocs) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of ExternalDocs.
func (e ExternalDocs) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of ExternalDocs.
func (e *ExternalDocs) UnmarshalJSON(data []byte) error
UnmarshalJSON sets ExternalDocs to a copy of data.
func (e *ExternalDocs) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if ExternalDocs does not comply with the OpenAPI
spec.
type FormatValidator[T any] interface {
Validate(value T) error
}
FormatValidator is an interface for custom format validators.
func NewCallbackValidator[T any](fn func(T) error) FormatValidator[T]
NewCallbackValidator creates a new FormatValidator that uses a callback
function to validate the value.
func NewIPValidator(isIPv4 bool) FormatValidator[string]
NewIPValidator creates a new FormatValidator that validates the value is an
IP address.
func NewRangeFormatValidator[T int64 | float64](min, max T) FormatValidator[T]
NewRangeFormatValidator creates a new FormatValidator that validates the
value is within a given range.
type Header struct {
Parameter
}
Header is specified by OpenAPI/Swagger 3.0 standard. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object
func (header Header) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (header Header) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Header.
func (header Header) MarshalYAML() (any, error)
MarshalYAML returns the JSON encoding of Header.
func (header *Header) SerializationMethod() (*SerializationMethod, error)
SerializationMethod returns a header's serialization method.
func (header *Header) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Header to a copy of data.
func (header *Header) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Header does not comply with the OpenAPI spec.
type HeaderRef struct {
// Extensions only captures fields starting with 'x-' as no other fields
// are allowed by the openapi spec.
Extensions map[string]any
Origin *Origin
Ref string
Value *Header
// Has unexported fields.
}
HeaderRef represents either a Header or a $ref to a Header. When serializing
and both fields are set, Ref is preferred over Value.
func (x *HeaderRef) CollectionName() string
CollectionName returns the JSON string used for a collection of these
components.
func (x *HeaderRef) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (x HeaderRef) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of HeaderRef.
func (x HeaderRef) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of HeaderRef.
func (x *HeaderRef) RefPath() *url.URL
RefPath returns the path of the $ref relative to the root document.
func (x *HeaderRef) RefString() string
RefString returns the $ref value.
func (x *HeaderRef) UnmarshalJSON(data []byte) error
UnmarshalJSON sets HeaderRef to a copy of data.
func (x *HeaderRef) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if HeaderRef does not comply with the OpenAPI
spec.
type Headers map[string]*HeaderRef
func (m Headers) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (headers *Headers) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Headers to a copy of data.
type Info struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Title string `json:"title" yaml:"title"` // Required
Description string `json:"description,omitempty" yaml:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
License *License `json:"license,omitempty" yaml:"license,omitempty"`
Version string `json:"version" yaml:"version"` // Required
}
Info is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#info-object
func (info Info) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Info.
func (info *Info) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Info.
func (info *Info) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Info to a copy of data.
func (info *Info) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Info does not comply with the OpenAPI spec.
type IntegerFormatValidator = FormatValidator[int64]
IntegerFormatValidator is a type alias for FormatValidator[int64]
type License struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Name string `json:"name" yaml:"name"` // Required
URL string `json:"url,omitempty" yaml:"url,omitempty"`
}
License is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#license-object
func (license License) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of License.
func (license License) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of License.
func (license *License) UnmarshalJSON(data []byte) error
UnmarshalJSON sets License to a copy of data.
func (license *License) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if License does not comply with the OpenAPI spec.
type Link struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
OperationRef string `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Parameters map[string]any `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Server *Server `json:"server,omitempty" yaml:"server,omitempty"`
RequestBody any `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
}
Link is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object
func (link Link) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of Link.
func (link Link) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of Link.
func (link *Link) UnmarshalJSON(data []byte) error
UnmarshalJSON sets Link to a copy of data.
func (link *Link) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if Link does not comply with the OpenAPI spec.
type LinkRef struct {
// Extensions only captures fields starting with 'x-' as no other fields
// are allowed by the openapi spec.
Extensions map[string]any
Origin *Origin
Ref string
Value *Link
// Has unexported fields.
}
LinkRef represents either a Link or a $ref to a Link. When serializing and
both fields are set, Ref is preferred over Value.
func (x *LinkRef) CollectionName() string
CollectionName returns the JSON string used for a collection of these
components.
func (x *LinkRef) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (x LinkRef) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of LinkRef.
func (x LinkRef) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of LinkRef.
func (x *LinkRef) RefPath() *url.URL
RefPath returns the path of the $ref relative to the root document.
func (x *LinkRef) RefString() string
RefString returns the $ref value.
func (x *LinkRef) UnmarshalJSON(data []byte) error
UnmarshalJSON sets LinkRef to a copy of data.
func (x *LinkRef) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if LinkRef does not comply with the OpenAPI spec.
type Links map[string]*LinkRef
func (m Links) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (links *Links) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON sets Links to a copy of data.
type Loader struct {
// IsExternalRefsAllowed enables visiting other files
IsExternalRefsAllowed bool
// IncludeOrigin specifies whether to include the origin of the OpenAPI elements
IncludeOrigin bool
// ReadFromURIFunc allows overriding the any file/URL reading func
ReadFromURIFunc ReadFromURIFunc
Context context.Context
// Has unexported fields.
}
Loader helps deserialize an OpenAPIv3 document
func NewLoader() *Loader
NewLoader returns an empty Loader
func (loader *Loader) LoadFromData(data []byte) (*T, error)
LoadFromData loads a spec from a byte array
func (loader *Loader) LoadFromDataWithPath(data []byte, location *url.URL) (*T, error)
LoadFromDataWithPath takes the OpenAPI document data in bytes and a path
where the resolver can find referred elements and returns a *T with all
resolved data or an error if unable to load data or resolve refs.
func (loader *Loader) LoadFromFile(location string) (*T, error)
LoadFromFile loads a spec from a local file path
func (loader *Loader) LoadFromIoReader(reader io.Reader) (*T, error)
LoadFromStdin loads a spec from io.Reader
func (loader *Loader) LoadFromStdin() (*T, error)
LoadFromStdin loads a spec from stdin
func (loader *Loader) LoadFromURI(location *url.URL) (*T, error)
LoadFromURI loads a spec from a remote URL
func (loader *Loader) ResolveRefsIn(doc *T, location *url.URL) (err error)
ResolveRefsIn expands references if for instance spec was just unmarshaled
type Location struct {
Line int `json:"line,omitempty" yaml:"line,omitempty"`
Column int `json:"column,omitempty" yaml:"column,omitempty"`
}
Location is a struct that contains the location of a field.
type MediaType struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Schema *SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty"`
Encoding map[string]*Encoding `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}
MediaType is specified by OpenAPI/Swagger 3.0 standard. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object
func NewMediaType() *MediaType
func (mediaType MediaType) JSONLookup(token string) (any, error)
JSONLookup implements
https://pkg.go.dev/github.com/go-openapi/jsonpointer#JSONPointable
func (mediaType MediaType) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of MediaType.
func (mediaType MediaType) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of MediaType.
func (mediaType *MediaType) UnmarshalJSON(data []byte) error
UnmarshalJSON sets MediaType to a copy of data.
func (mediaType *MediaType) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if MediaType does not comply with the OpenAPI
spec.
func (mediaType *MediaType) WithEncoding(name string, enc *Encoding) *MediaType
func (mediaType *MediaType) WithExample(name string, value any) *MediaType
func (mediaType *MediaType) WithSchema(schema *Schema) *MediaType
func (mediaType *MediaType) WithSchemaRef(schema *SchemaRef) *MediaType
type MultiError []error
MultiError is a collection of errors, intended for when multiple issues need
to be reported upstream
func (me MultiError) As(target any) bool
As allows you to use `errors.As()` to set target to the first error within
the multi error that matches the target type
func (me MultiError) Error() string
func (me MultiError) Is(target error) bool
Is allows you to determine if a generic error is in fact a MultiError using
`errors.Is()` It will also return true if any of the contained errors match
target
type NewCallbackOption func(*Callback)
NewCallbackOption describes options to NewCallback func
func WithCallback(cb string, pathItem *PathItem) NewCallbackOption
WithCallback adds Callback as an option to NewCallback
type NewPathsOption func(*Paths)
NewPathsOption describes options to NewPaths func
func WithPath(path string, pathItem *PathItem) NewPathsOption
WithPath adds a named path item
type NewResponsesOption func(*Responses)
NewResponsesOption describes options to NewResponses func
func WithName(name string, response *Response) NewResponsesOption
WithName adds a name-keyed Response
func WithStatus(status int, responseRef *ResponseRef) NewResponsesOption
WithStatus adds a status code keyed ResponseRef
type NumberFormatValidator = FormatValidator[float64]
NumberFormatValidator is a type alias for FormatValidator[float64]
type OAuthFlow struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes StringMap `json:"scopes" yaml:"scopes"` // required
}
OAuthFlow is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flow-object
func (flow OAuthFlow) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of OAuthFlow.
func (flow OAuthFlow) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of OAuthFlow.
func (flow *OAuthFlow) UnmarshalJSON(data []byte) error
UnmarshalJSON sets OAuthFlow to a copy of data.
func (flow *OAuthFlow) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if OAuthFlows does not comply with the OpenAPI
spec.
type OAuthFlows struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
Implicit *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
Password *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}
OAuthFlows is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flows-object
func (flows OAuthFlows) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of OAuthFlows.
func (flows OAuthFlows) MarshalYAML() (any, error)
MarshalYAML returns the YAML encoding of OAuthFlows.
func (flows *OAuthFlows) UnmarshalJSON(data []byte) error
UnmarshalJSON sets OAuthFlows to a copy of data.
func (flows *OAuthFlows) Validate(ctx context.Context, opts ...ValidationOption) error
Validate returns an error if OAuthFlows does not comply with the OpenAPI
spec.
type Operation struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`
// Optional tags for documentation.
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
// Optional short summary.
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
// Optional description. Should use CommonMark syntax.
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// Optional operation ID.
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
// Optional parameters.
Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
// Optional body parameter.
RequestBody *RequestBodyRef `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
// Responses.
Responses *Responses `json:"responses" yaml:"responses"` // Required