Skip to content

Commit 69fe7a8

Browse files
committed
Add date format to OpenAPI 3.0
This shouldn't've been removed in: ccffac7 I was under the impression that it would be provided by draft4 since that's openapi30's meta schema, but it's not in that spec. OpenAPI 3.0 formats listed here: https://spec.openapis.org/oas/v3.0.3#data-types @ahx noticed this here: #149 (comment)
1 parent 4f9d6e4 commit 69fe7a8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/json_schemer/openapi30/meta.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module OpenAPI30
55
# https://spec.openapis.org/oas/v3.0.3#data-types
66
FORMATS = OpenAPI31::FORMATS.merge(
77
'byte' => proc { |instance, _value| Format.decode_content_encoding(instance, 'base64').first },
8-
'binary' => proc { |instance, _value| instance.is_a?(String) && instance.encoding == Encoding::ASCII_8BIT }
8+
'binary' => proc { |instance, _value| instance.is_a?(String) && instance.encoding == Encoding::ASCII_8BIT },
9+
'date' => Format::DATE
910
)
1011
SCHEMA = {
1112
'id' => 'json-schemer://openapi30/schema',

test/open_api_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ def test_openapi30_formats
735735
'd' => { 'format' => 'double' },
736736
'e' => { 'format' => 'password' },
737737
'f' => { 'format' => 'byte' },
738-
'g' => { 'format' => 'binary' }
738+
'g' => { 'format' => 'binary' },
739+
'h' => { 'format' => 'date' },
740+
'i' => { 'format' => 'date-time' }
739741
}
740742
}
741743

@@ -756,6 +758,10 @@ def test_openapi30_formats
756758
assert(schemer.valid?({ 'f' => 'IQ==' }))
757759
refute(schemer.valid?({ 'g' => '!' }))
758760
assert(schemer.valid?({ 'g' => '!'.b }))
761+
refute(schemer.valid?({ 'h' => '2001-02-03T04:05:06.123456789+07:00' }))
762+
assert(schemer.valid?({ 'h' => '2001-02-03' }))
763+
refute(schemer.valid?({ 'i' => '2001-02-03' }))
764+
assert(schemer.valid?({ 'i' => '2001-02-03T04:05:06.123456789+07:00' }))
759765
end
760766

761767
def test_unsupported_openapi_version

0 commit comments

Comments
 (0)