Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time format #276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions lib/prmd/schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'json'
require 'yaml'
require_relative 'time_to_json_schema'

# :nodoc:
module Prmd
Expand Down Expand Up @@ -189,6 +190,7 @@ def to_yaml
#
# @return [String]
def to_s
Time.prepend Prmd::TimeToJSONSchema
to_json
end

Expand Down
7 changes: 7 additions & 0 deletions lib/prmd/time_to_json_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Prmd
module TimeToJSONSchema
def to_json(options = {})
"\"#{xmlschema}\""
end
end
end
6 changes: 6 additions & 0 deletions test/schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ def test_dereference_with_local_context
user_id = user_input_schema['definitions']['user']['definitions']['id']
assert_equal(value, { 'override' => true }.merge(user_id))
end

def test_include_time
time = user_input_schema['definitions']['user']['definitions']['created_at']['example']
json_schema_format = "\"#{Time.parse(time).xmlschema}\""
assert_equal(time.to_json, json_schema_format)
end
end
14 changes: 14 additions & 0 deletions test/time_to_json_schema_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require File.expand_path('./helpers', File.dirname(__FILE__))

module Prmd
class TimeToJSONSchemaTest < Minitest::Test
def time
Time.parse('2016-01-01 00:00:00 JST')
end

def test_to_json
Time.prepend TimeToJSONSchema
assert_equal time.to_json, "\"#{time.xmlschema}\""
end
end
end