forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomodel.go
657 lines (566 loc) · 17.2 KB
/
nomodel.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
// Copyright 2015 go-swagger maintainers
//
// 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.
package models
import (
"time"
"github.com/go-openapi/strfmt"
"github.com/go-swagger/go-swagger/fixtures/goparsing/classification/transitive/mods"
)
// NoModel is a struct without an annotation.
// NoModel exists in a package
// but is not annotated with the swagger model annotations
// so it should now show up in a test.
//
type NoModel struct {
// ID of this no model instance.
// ids in this application start at 11 and are smaller than 1000
//
// required: true
// minimum: > 10
// maximum: < 1000
// default: 11
ID int64 `json:"id"`
Ignored string `json:"-"`
IgnoredOther string `json:"-,omitempty"`
// A field which has omitempty set but no name
NoNameOmitEmpty string `json:",omitempty"`
// The Score of this model
//
// required: true
// minimum: 3
// maximum: 45
// multiple of: 3
// example: 27
Score int32 `json:"score"`
// Name of this no model instance
//
// min length: 4
// max length: 50
// pattern: [A-Za-z0-9-.]*
// required: true
//
// Extensions:
// ---
// x-property-value: value
// x-property-array:
// - value1
// - value2
// x-property-array-obj:
// - name: obj
// value: field
// ---
//
Name string `json:"name"`
// Created holds the time when this entry was created
//
// required: false
// read only: true
Created strfmt.DateTime `json:"created"`
// GoTimeCreated holds the time when this entry was created in go time.Time
//
// required: false
GoTimeCreated time.Time `json:"gocreated"`
// a FooSlice has foos which are strings
//
// min items: 3
// max items: 10
// unique: true
// items.minLength: 3
// items.maxLength: 10
// items.pattern: \w+
FooSlice []string `json:"foo_slice"`
// a TimeSlice is a slice of times
//
// min items: 3
// max items: 10
// unique: true
TimeSlice []time.Time `json:"time_slice"`
// a BarSlice has bars which are strings
//
// min items: 3
// max items: 10
// unique: true
// items.minItems: 4
// items.maxItems: 9
// items.items.minItems: 5
// items.items.maxItems: 8
// items.items.items.minLength: 3
// items.items.items.maxLength: 10
// items.items.items.pattern: \w+
BarSlice [][][]string `json:"bar_slice"`
// a DeepSlice has bars which are time
//
// min items: 3
// max items: 10
// unique: true
// items.minItems: 4
// items.maxItems: 9
// items.items.minItems: 5
// items.items.maxItems: 8
DeepTimeSlice [][][]time.Time `json:"deep_time_slice"`
// the items for this order
Items []struct {
// ID of this no model instance.
// ids in this application start at 11 and are smaller than 1000
//
// required: true
// minimum: > 10
// maximum: < 1000
// default: 11
ID int32 `json:"id"`
// The Pet to add to this NoModel items bucket.
// Pets can appear more than once in the bucket
//
// required: true
Pet *mods.Pet `json:"pet"`
// The amount of pets to add to this bucket.
//
// required: true
// minimum: 1
// maximum: 10
Quantity int16 `json:"quantity"`
// A dummy expiration date.
//
// required: true
Expiration time.Time `json:"expiration"`
// Notes to add to this item.
// This can be used to add special instructions.
//
// required: false
Notes string `json:"notes"`
AlsoIgnored string `json:"-"`
} `json:"items"`
}
// A OtherTypes struct contains type aliases
type OtherTypes struct {
Named SomeStringType `json:"named"`
Numbered SomeIntType `json:"numbered"`
Dated SomeTimeType `json:"dated"`
Timed SomeTimedType `json:"timed"`
Petted SomePettedType `json:"petted"`
Somethinged SomethingType `json:"somethinged"`
StrMap SomeStringMap `json:"strMap"`
StrArrMap SomeArrayStringMap `json:"strArrMap"`
ManyNamed SomeStringsType `json:"manyNamed"`
ManyNumbered SomeIntsType `json:"manyNumbered"`
ManyDated SomeTimesType `json:"manyDated"`
ManyTimed SomeTimedsType `json:"manyTimed"`
ManyPetted SomePettedsType `json:"manyPetted"`
ManySomethinged SomethingsType `json:"manySomethinged"`
Nameds []SomeStringType `json:"nameds"`
Numbereds []SomeIntType `json:"numbereds"`
Dateds []SomeTimeType `json:"dateds"`
Timeds []SomeTimedType `json:"timeds"`
Petteds []SomePettedType `json:"petteds"`
Somethingeds []SomethingType `json:"somethingeds"`
ModsNamed mods.SomeStringType `json:"modsNamed"`
ModsNumbered mods.SomeIntType `json:"modsNumbered"`
ModsDated mods.SomeTimeType `json:"modsDated"`
ModsTimed mods.SomeTimedType `json:"modsTimed"`
ModsPetted mods.SomePettedType `json:"modsPetted"`
ModsNameds []mods.SomeStringType `json:"modsNameds"`
ModsNumbereds []mods.SomeIntType `json:"modsNumbereds"`
ModsDateds []mods.SomeTimeType `json:"modsDateds"`
ModsTimeds []mods.SomeTimedType `json:"modsTimeds"`
ModsPetteds []mods.SomePettedType `json:"modsPetteds"`
ManyModsNamed mods.SomeStringsType `json:"manyModsNamed"`
ManyModsNumbered mods.SomeIntsType `json:"manyModsNumbered"`
ManyModsDated mods.SomeTimesType `json:"manyModsDated"`
ManyModsTimed mods.SomeTimedsType `json:"manyModsTimed"`
ManyModsPetted mods.SomePettedsType `json:"manyModsPetted"`
ManyModsPettedPtr mods.SomePettedsPtrType `json:"manyModsPettedPtr"`
NamedAlias SomeStringTypeAlias `json:"namedAlias"`
NumberedAlias SomeIntTypeAlias `json:"numberedAlias"`
NamedsAlias []SomeStringTypeAlias `json:"namedsAlias"`
NumberedsAlias []SomeIntTypeAlias `json:"numberedsAlias"`
}
// A SimpleOne is a model with a few simple fields
type SimpleOne struct {
ID int64 `json:"id"`
Name string `json:"name"`
Age int32 `json:"age"`
}
// A ComplexerOne is composed of a SimpleOne and some extra fields
type ComplexerOne struct {
SimpleOne
mods.NotSelected
mods.Notable
CreatedAt strfmt.DateTime `json:"createdAt"`
}
// An OverridingOne is composed of a SimpleOne and overrides a field
type OverridingOne struct {
SimpleOne
Age int64
}
// An OverridingOneIgnore is composed of a SimpleOne and overrides a field to ignore it
type OverridingOneIgnore struct {
SimpleOne
Age int32 `json:"-"`
}
// An AllOfModel is composed out of embedded structs but it should build
// an allOf property
type AllOfModel struct {
// swagger:allOf
SimpleOne
// swagger:allOf
mods.Notable
Something // not annotated with anything, so should be included
CreatedAt strfmt.DateTime `json:"createdAt"`
}
// An Embedded is to be embedded in EmbeddedStarExpr
type Embedded struct {
EmbeddedMember int64 `json:"embeddedMember"`
}
// An EmbeddedStarExpr for testing the embedded StarExpr
type EmbeddedStarExpr struct {
*Embedded
NotEmbedded int64 `json:"notEmbedded"`
}
// A PrimateModel is a struct with nothing but builtins.
//
// It only has values 1 level deep and each of those is of a very simple
// builtin type.
type PrimateModel struct {
A bool `json:"a"`
B rune `json:"b"`
C string `json:"c"`
D int `json:"d"`
E int8 `json:"e"`
F int16 `json:"f"`
G int32 `json:"g"`
H int64 `json:"h"`
I uint `json:"i"`
J uint8 `json:"j"`
K uint16 `json:"k"`
L uint32 `json:"l"`
M uint64 `json:"m"`
N float32 `json:"n"`
O float64 `json:"o"`
P byte `json:"p"`
Q uintptr `json:"q"`
}
// A FormattedModel is a struct with only strfmt types
//
// It only has values 1 level deep and is used for testing the conversion
type FormattedModel struct {
A strfmt.Base64 `json:"a"`
B strfmt.CreditCard `json:"b"`
C strfmt.Date `json:"c"`
D strfmt.DateTime `json:"d"`
E strfmt.Duration `json:"e"`
F strfmt.Email `json:"f"`
G strfmt.HexColor `json:"g"`
H strfmt.Hostname `json:"h"`
I strfmt.IPv4 `json:"i"`
J strfmt.IPv6 `json:"j"`
K strfmt.ISBN `json:"k"`
L strfmt.ISBN10 `json:"l"`
M strfmt.ISBN13 `json:"m"`
N strfmt.RGBColor `json:"n"`
O strfmt.SSN `json:"o"`
P strfmt.URI `json:"p"`
Q strfmt.UUID `json:"q"`
R strfmt.UUID3 `json:"r"`
S strfmt.UUID4 `json:"s"`
T strfmt.UUID5 `json:"t"`
U strfmt.MAC `json:"u"`
}
// A SimpleComplexModel is a struct with only other struct types
//
// It doesn't have slices or arrays etc but only complex types
// so also no primitives or string formatters
type SimpleComplexModel struct {
Top Something `json:"top"`
NotSel mods.NotSelected `json:"notSel"`
Emb struct {
CID int64 `json:"cid"`
Baz string `json:"baz"`
} `json:"emb"`
}
// Pointdexter is a struct with only pointers
type Pointdexter struct {
ID *int64 `json:"id"`
Name *string `json:"name"`
T *strfmt.UUID5 `json:"t"`
Top *Something `json:"top"`
NotSel *mods.NotSelected `json:"notSel"`
Emb *struct {
CID *int64 `json:"cid"`
Baz *string `json:"baz"`
} `json:"emb"`
}
// A SliceAndDice struct contains only slices
//
// the elements of the slices are structs, primitives or string formats
// there is also a pointer version of each property
type SliceAndDice struct {
IDs []int64 `json:"ids"`
Names []string `json:"names"`
UUIDs []strfmt.UUID `json:"uuids"`
Tops []Something `json:"tops"`
NotSels []mods.NotSelected `json:"notSels"`
Embs []struct {
CID []int64 `json:"cid"`
Baz []string `json:"baz"`
} `json:"embs"`
PtrIDs []*int64 `json:"ptrIds"`
PtrNames []*string `json:"ptrNames"`
PtrUUIDs []*strfmt.UUID `json:"ptrUuids"`
PtrTops []*Something `json:"ptrTops"`
PtrNotSels []*mods.NotSelected `json:"ptrNotSels"`
PtrEmbs []*struct {
PtrCID []*int64 `json:"ptrCid"`
PtrBaz []*string `json:"ptrBaz"`
} `json:"ptrEmbs"`
}
// A MapTastic struct contains only maps
//
// the values of the maps are structs, primitives or string formats
// there is also a pointer version of each property
type MapTastic struct {
IDs map[string]int64 `json:"ids"`
Names map[string]string `json:"names"`
UUIDs map[string]strfmt.UUID `json:"uuids"`
Tops map[string]Something `json:"tops"`
NotSels map[string]mods.NotSelected `json:"notSels"`
Embs map[string]struct {
CID map[string]int64 `json:"cid"`
Baz map[string]string `json:"baz"`
} `json:"embs"`
PtrIDs map[string]*int64 `json:"ptrIds"`
PtrNames map[string]*string `json:"ptrNames"`
PtrUUIDs map[string]*strfmt.UUID `json:"ptrUuids"`
PtrTops map[string]*Something `json:"ptrTops"`
PtrNotSels map[string]*mods.NotSelected `json:"ptrNotSels"`
PtrEmbs map[string]*struct {
PtrCID map[string]*int64 `json:"ptrCid"`
PtrBaz map[string]*string `json:"ptrBaz"`
} `json:"ptrEmbs"`
}
// An Interfaced struct contains objects with interface definitions
type Interfaced struct {
CustomData interface{} `json:"custom_data"`
}
// A BaseStruct is a struct that has subtypes.
//
// it should deserialize into one of the struct types that
// enlist for being implementations of this struct
//
// swagger:model animal
type BaseStruct struct {
// ID of this no model instance.
// ids in this application start at 11 and are smaller than 1000
//
// required: true
// minimum: > 10
// maximum: < 1000
ID int64 `json:"id"`
// Name of this no model instance
//
// min length: 4
// max length: 50
// pattern: [A-Za-z0-9-.]*
// required: true
Name string `json:"name"`
// StructType the type of this polymorphic model
//
// discriminator: true
StructType string `json:"jsonClass"`
}
/* TODO: implement this in the scanner
// A Lion is a struct that "subtypes" the BaseStruct
//
// it does so because it included the fields in the struct body
// The scanner assumes it will follow the rules and describes this type
// as discriminated in the swagger spec based on the discriminator value
// annotation.
//
// swagger:model lion
// swagger:discriminatorValue animal org.horrible.java.fqpn.TheLionDataObjectFactoryInstanceServiceImpl
type Lion struct {
// ID of this no model instance.
// ids in this application start at 11 and are smaller than 1000
//
// required: true
// minimum: > 10
// maximum: < 1000
ID int64 `json:"id"`
// Name of this no model instance
//
// min length: 4
// max length: 50
// pattern: [A-Za-z0-9-.]*
// required: true
Name string `json:"name"`
// StructType the type of this polymorphic model
StructType string `json:"jsonClass"`
// Leader is true when this is the leader of its group
//
// default value: false
Leader bool `json:"leader"`
}
*/
// A Giraffe is a struct that embeds BaseStruct
//
// the annotation is not necessary here because of inclusion
// of a discriminated type
// it infers the name of the x-class value from its context
//
// swagger:model giraffe
type Giraffe struct {
// swagger:allOf
BaseStruct
// NeckSize the size of the neck of this giraffe
NeckSize int64 `json:"neckSize"`
}
// A Gazelle is a struct is discriminated for BaseStruct.
//
// The struct includes the BaseStruct and that embedded value
// is annotated with the discriminator value annotation so it
// where it only requires 1 argument because it knows which
// discriminator type this belongs to
//
// swagger:model gazelle
type Gazelle struct {
// swagger:allOf a.b.c.d.E
BaseStruct
// The size of the horns
HornSize float32 `json:"hornSize"`
}
// Identifiable is an interface for things that have an ID
type Identifiable interface {
// ID of this no model instance.
// ids in this application start at 11 and are smaller than 1000
//
// required: true
// minimum: > 10
// maximum: < 1000
// swagger:name id
ID() int64
}
// WaterType is an interface describing a water type
//
// swagger:model water
type WaterType interface {
// swagger:name sweetWater
SweetWater() bool
// swagger:name saltWater
SaltWater() bool
}
// Fish represents a base type implemented as interface
// the nullary methods of this interface will be included as
//
// swagger:model fish
type Fish interface {
Identifiable // interfaces like this are included as if they were defined directly on this type
// embeds decorated with allOf are included as refs
// swagger:allOf
WaterType
// swagger:allOf
mods.ExtraInfo
mods.EmbeddedColor
Items(id, size int64) []string
// Name of this no model instance
//
// min length: 4
// max length: 50
// pattern: [A-Za-z0-9-.]*
// required: true
// swagger:name name
Name() string
// StructType the type of this polymorphic model
// Discriminator: true
// swagger:name jsonClass
StructType() string
}
// TeslaCar is a tesla car
//
// swagger:model
type TeslaCar interface {
// The model of tesla car
//
// discriminated: true
// swagger:name model
Model() string
// AutoPilot returns true when it supports autopilot
// swagger:name autoPilot
AutoPilot() bool
}
// The ModelS version of the tesla car
//
// swagger:model modelS
type ModelS struct {
// swagger:allOf com.tesla.models.ModelS
TeslaCar
// The edition of this Model S
Edition string `json:"edition"`
}
// The ModelX version of the tesla car
//
// swagger:model modelX
type ModelX struct {
// swagger:allOf com.tesla.models.ModelX
TeslaCar
// The number of doors on this Model X
Doors int `json:"doors"`
}
// The ModelA version of the tesla car
//
// swagger:model modelA
type ModelA struct {
Tesla TeslaCar
// The number of doors on this Model A
Doors int `json:"doors"`
}
// Cars is a collection of cars
//
// swagger:model cars
type Cars struct {
Cars []*TeslaCar `json:"cars"`
}
// JSONString has fields with ",string" JSON directives.
//
// swagger:model jsonString
type JSONString struct {
// Should be encoded as a string with string format "integer"
SomeInt int `json:"someInt,string"`
SomeInt8 int8 `json:"someInt8,string"`
SomeInt16 int16 `json:"someInt16,string"`
SomeInt32 int32 `json:"someInt32,string"`
SomeInt64 int64 `json:"someInt64,string"`
SomeUint uint `json:"someUint,string"`
SomeUint8 uint8 `json:"someUint8,string"`
SomeUint16 uint16 `json:"someUint16,string"`
SomeUint32 uint32 `json:"someUint32,string"`
SomeUint64 uint64 `json:"someUint64,string"`
// Should be encoded as a string with string format "double"
SomeFloat64 float64 `json:"someFloat64,string"`
// Should be encoded as a string with no format
SomeString string `json:"someString,string"`
// Should be encoded as a string with no format
SomeBool bool `json:"someBool,string"`
// The ",string" directive should be ignore before the type isn't scalar
SomethingElse Cars `json:"somethingElse,string"`
}
// IgnoredFields demostrates the use of swagger:ignore on struct fields.
//
// swagger:model ignoredFields
type IgnoredFields struct {
SomeIncludedField string `json:"someIncludedField"`
// swagger:ignore
SomeIgnoredField string `json:"someIgnoredField"`
// This swagger:ignore tag won't work - it needs to be in the field's doc
// block
SomeErroneouslyIncludedField string `json:"someErroneouslyIncludedField"` // swagger:ignore
}