-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
132 lines (121 loc) · 3.66 KB
/
common.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
package chioas
import (
"encoding/json"
"github.com/go-chi/chi/v5"
"math"
)
// OasVersion is the default OAS version for docs
var OasVersion = "3.0.3"
// ApplyMiddlewares is a function that returns middlewares to be applied to a Path or the api root
//
// can be used on Path.ApplyMiddlewares and Definition.ApplyMiddlewares (for api root)
type ApplyMiddlewares func(thisApi any) chi.Middlewares
// DisablerFunc is a function that can be used by Path.Disabled
type DisablerFunc func() bool
const (
root = "/"
hdrAllow = "Allow"
tagNameAnyOf = "anyOf"
tagNameAllOf = "allOf"
tagNameApplicationJson = contentTypeJson
tagNameComponents = "components"
tagNameContact = "contact"
tagNameContent = "content"
tagNameDefault = "default"
tagNameDeprecated = "deprecated"
tagNameDescription = "description"
tagNameDiscriminator = "discriminator"
tagNameEmail = "email"
tagNameEnum = "enum"
tagNameExample = "example"
tagNameExamples = "examples"
tagNameExclusiveMaximum = "exclusiveMaximum"
tagNameExclusiveMinimum = "exclusiveMinimum"
tagNameExternalDocs = "externalDocs"
tagNameFormat = "format"
tagNameIn = "in"
tagNameInfo = "info"
tagNameItems = "items"
tagNameItemType = "itemType"
tagNameLicense = "license"
tagNameMapping = "mapping"
tagNameMaxItems = "maxItems"
tagNameMaxLength = "maxLength"
tagNameMaxProperties = "maxProperties"
tagNameMaximum = "maximum"
tagNameMinItems = "minItems"
tagNameMinLength = "minLength"
tagNameMinProperties = "minProperties"
tagNameMinimum = "minimum"
tagNameMultipleOf = "multipleOf"
tagNameName = "name"
tagNameNullable = "nullable"
tagNameOneOf = "oneOf"
tagNameOpenApi = "openapi"
tagNameOperationId = "operationId"
tagNameParameters = "parameters"
tagNamePaths = "paths"
tagNamePattern = "pattern"
tagNameProperties = "properties"
tagNamePropertyName = "propertyName"
tagNameRef = "$ref"
tagNameRequestBodies = "requestBodies"
tagNameRequestBody = "requestBody"
tagNameRequired = "required"
tagNameResponses = "responses"
tagNameSchema = "schema"
tagNameSchemas = "schemas"
tagNameScheme = "scheme"
tagNameSecurity = "security"
tagNameSecuritySchemes = "securitySchemes"
tagNameServers = "servers"
tagNameSummary = "summary"
tagNameTags = "tags"
tagNameTermsOfService = "termsOfService"
tagNameTitle = "title"
tagNameType = "type"
tagNameUniqueItems = "uniqueItems"
tagNameUrl = "url"
tagNameValue = "value"
tagNameVersion = "version"
tagValuePath = "path"
tagValueQuery = "query"
tagValueTypeObject = "object"
tagValueTypeArray = "array"
tagValueTypeString = "string"
tagValueTypeNull = "null"
tagValueTypeInteger = "integer"
tagValueTypeNumber = "number"
tagValueTypeBoolean = "boolean"
)
func nilString(v string) (result any) {
result = v
if v == "" {
result = nil
}
return
}
func nilBool(v bool) (result any) {
result = v
if !v {
result = nil
}
return
}
func nilNumber(n json.Number) (result any) {
if n != "" {
if i, err := n.Int64(); err == nil {
result = i
} else if f, err := n.Float64(); err == nil && !math.IsNaN(f) && !math.IsInf(f, 0) {
result = n
}
}
return
}
func nilUint(v uint) (result any) {
result = v
if v == 0 {
result = nil
}
return
}