diff --git a/lib/prmd/schema.rb b/lib/prmd/schema.rb index a8983f94..44030931 100644 --- a/lib/prmd/schema.rb +++ b/lib/prmd/schema.rb @@ -1,5 +1,6 @@ require 'json' require 'yaml' +require_relative 'time_to_json_schema' # :nodoc: module Prmd @@ -189,6 +190,7 @@ def to_yaml # # @return [String] def to_s + Time.prepend Prmd::TimeToJSONSchema to_json end diff --git a/lib/prmd/time_to_json_schema.rb b/lib/prmd/time_to_json_schema.rb new file mode 100644 index 00000000..933fd1d7 --- /dev/null +++ b/lib/prmd/time_to_json_schema.rb @@ -0,0 +1,7 @@ +module Prmd + module TimeToJSONSchema + def to_json(options = {}) + "\"#{xmlschema}\"" + end + end +end diff --git a/test/schema_test.rb b/test/schema_test.rb index 09b68d1b..aa874128 100644 --- a/test/schema_test.rb +++ b/test/schema_test.rb @@ -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 diff --git a/test/time_to_json_schema_test.rb b/test/time_to_json_schema_test.rb new file mode 100644 index 00000000..91b6a576 --- /dev/null +++ b/test/time_to_json_schema_test.rb @@ -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