This repository was archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintermediate_slice.go
More file actions
98 lines (77 loc) · 2.14 KB
/
intermediate_slice.go
File metadata and controls
98 lines (77 loc) · 2.14 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
package main
import (
"github.com/go-openapi/spec"
"strconv"
)
type SliceIntermediate struct {
Name string // Name in Go struct.
Type string // Go type
JsonName string // JSON name.
JsonOmitEmpty bool // If the omitempty flag was given in the JSON.
ValueType *MemberIntermediate
Description string
Validations Validator
Deprecated bool
PackageName string // Necessary for canonical and swagger names.
PackagePath string
}
func (this *SliceIntermediate) IsRequired() bool {
return this.Validations.IsRequired()
}
func (this *SliceIntermediate) GoType() string {
return this.Type
}
func (this *SliceIntermediate) SetPackagePath(s string) {
this.PackagePath = s
}
func (this *SliceIntermediate) GetPackagePath() string {
return this.PackagePath
}
func (this *SliceIntermediate) SetPackageName(s string) {
this.PackageName = s
}
func (this *SliceIntermediate) Schema() *spec.Schema {
schema := new(spec.Schema)
name := this.Name
if this.JsonName != "" {
name = this.JsonName
}
schema.Title = name
schema.Description = this.Description
schema.Items = new(spec.SchemaOrArray)
schema.Typed("array", "")
schema.Items.Schema = this.ValueType.Schema()
if this.Validations.Min() >= 0 {
schema.WithMinItems(int64(this.Validations.Min()))
}
if this.Validations.Max() >= 0 {
schema.WithMaxItems(int64(this.Validations.Max()))
}
if this.Validations.Length() >= 0 {
schema.WithMinItems(int64(this.Validations.Length()))
schema.WithMaxItems(int64(this.Validations.Length()))
}
if s, ok := this.Validations.Equals(); ok {
d, err := strconv.ParseInt(s, 10, 64)
if err == nil {
schema.WithMinItems(d)
schema.WithMaxItems(d)
}
}
if this.Validations.GreaterThan() >= 0 {
schema.WithMinItems(int64(this.Validations.GreaterThan() + 1))
}
if this.Validations.LessThan() >= 0 {
schema.WithMaxItems(int64(this.Validations.LessThan() - 1))
}
return schema
}
//func (this *SliceIntermediate) DefineDefinitions(referencingPackagePath string) error {
//
// err := this.ValueType.DefineDefinitions(referencingPackagePath)
// if err != nil {
// return errors.Stack(err)
// }
//
// return nil
//}