-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_type.go
40 lines (33 loc) · 1.07 KB
/
data_type.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
package openapi
import (
"slices"
"github.com/MarkRosemaker/errpath"
)
// Data types in the OAS are based on the types supported by the JSON Schema Specification Draft 2020-12.
// Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part.
// Models are defined using the Schema Object, which is a superset of JSON Schema Specification Draft 2020-12.
//
// ([Specification])
//
// [Specification]: https://spec.openapis.org/oas/v3.1.0#data-types
type DataType string
const (
TypeInteger DataType = "integer" // format: int32, int64
TypeNumber DataType = "number" // format: float, double
TypeString DataType = "string" // format: password
TypeArray DataType = "array"
TypeBoolean DataType = "boolean"
TypeObject DataType = "object"
)
var allDataTypes = []DataType{
TypeInteger, TypeNumber, TypeString, TypeArray, TypeBoolean, TypeObject,
}
func (d DataType) Validate() error {
if slices.Contains(allDataTypes, d) {
return nil
}
return &errpath.ErrInvalid[DataType]{
Value: d,
Enum: allDataTypes,
}
}