Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion data_type_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
FormatDateBasic Format = "date-basic"
// FormatDateTime represents a date-time.
FormatDateTime Format = "date-time"
// FormatDateTimeMs represents a date-time written as an integer of unix milliseconds, such as 1795464914000. It is
// not one of JSON Schema's formats, but some APIs write a time this way.
FormatDateTimeMs Format = "date-time-ms"
// FormatDuration represents a duration.
FormatDuration Format = "duration"
// FormatEmail represents an email.
Expand All @@ -64,7 +67,7 @@ var allFormats = []Format{
FormatUint, FormatUint32, FormatUint64,
FormatFloat, FormatDouble,
FormatByte, FormatBinary,
FormatDate, FormatDateBasic, FormatDateTime, FormatDuration,
FormatDate, FormatDateBasic, FormatDateTime, FormatDateTimeMs, FormatDuration,
FormatEmail, FormatPassword,
FormatUUID,
FormatURI, FormatURIRef, FormatZipCode,
Expand Down
2 changes: 1 addition & 1 deletion data_type_format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/MarkRosemaker/openapi"
)

const validFormats = `"int32", "int64", "uint", "uint32", "uint64", "float", "double", "byte", "binary", "date", "date-basic", "date-time", "duration", "email", "password", "uuid", "uri", "uriref", "zip-code", "ipv4", "ipv6"`
const validFormats = `"int32", "int64", "uint", "uint32", "uint64", "float", "double", "byte", "binary", "date", "date-basic", "date-time", "date-time-ms", "duration", "email", "password", "uuid", "uri", "uriref", "zip-code", "ipv4", "ipv6"`

func TestFormat(t *testing.T) {
// test a valid data type format
Expand Down
2 changes: 1 addition & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (s *Schema) validateFormat() error {
var types string

switch s.Format {
case FormatInt32, FormatInt64, FormatUint, FormatUint32, FormatUint64:
case FormatInt32, FormatInt64, FormatUint, FormatUint32, FormatUint64, FormatDateTimeMs:
if !s.allows(TypeInteger) {
types = "integer"
}
Expand Down
4 changes: 4 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func TestSchema_Validate_Error(t *testing.T) {
Type: openapi.TypeBoolean,
Format: openapi.FormatDuration,
}, `format ("duration") is invalid: only valid for integer or string type, got boolean`},
{openapi.Schema{
Type: openapi.TypeString,
Format: openapi.FormatDateTimeMs,
}, `format ("date-time-ms") is invalid: only valid for integer type, got string`},
{openapi.Schema{
Type: openapi.TypeBoolean,
Items: &openapi.Schema{},
Expand Down
6 changes: 6 additions & 0 deletions testdata/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@
"format": "date-basic",
"example": "20260320"
},
"seen": {
"description": "a time in unix milliseconds",
"type": "integer",
"format": "date-time-ms",
"example": 1795464914000
},
"owner": {
"description": "a reference with keywords beside it",
"deprecated": true,
Expand Down
Loading