json_world 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe5ebf1266b4198d59b126441e76219cd92d43ea
4
- data.tar.gz: dc88a29966be7f7bd88a1160edc7a2f76f7c22a3
3
+ metadata.gz: a5aef48228e4c1d49717c2f834412ea45ddc98ae
4
+ data.tar.gz: c1ce06838c98f6a6b18c4dbf834619879b44eb7f
5
5
  SHA512:
6
- metadata.gz: f81ada767ec7fbb16a19ba47243ed0c4bc9873d228af25469bbca0681a7f1002e5c396e70dca21db6ae0ccf8eeb89e4739791a51ca3bfd94585b53b0b79d68d3
7
- data.tar.gz: 271631c6fce118d0cfec526c0247d23667430a8dd110ed591181629fe10dbb8e872a1d24001d7390d462720c09bfdbf15b6ddd15ad71ef24fe72d5103de9fc92
6
+ metadata.gz: 3db2e0a659ba8b9c559e8862eab6a88f76de7a87f49961743b9b19d54b7eef854d15a52acaae6c5da9220345f1a2d0cc7855fcf8c34744d948ab7c76d3a3bdea
7
+ data.tar.gz: 70522ff96af036d7ab5b20c6e830173e3e4ca68613ce70bce2d5ef7532148738401a184a72f2fce98daecb18d6595c2f425fb344115dd85c5f589b7515505ed2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.0
2
+ - Support :links option on embedding other resource as property
3
+
1
4
  ## 0.1.4
2
5
  - Rename as_json_schema_without_link with as_json_schema_without_links
3
6
 
@@ -14,18 +14,26 @@ module JsonWorld
14
14
 
15
15
  # @return [Hash{Symbol => Object}]
16
16
  def as_json_schema
17
- @options[:type].try(:as_json_schema_without_links) || {
18
- description: description,
19
- example: example,
20
- format: format_type,
21
- items: items_as_json_schema,
22
- pattern: pattern_in_string,
23
- properties: properties_as_json_schema,
24
- required: required_property_names,
25
- type: type,
26
- uniqueItems: unique_flag,
27
- }.reject do |_key, value|
28
- value.nil? || value.respond_to?(:empty?) && value.empty?
17
+ if has_json_schema_compatible_type?
18
+ if @options[:links]
19
+ @options[:type].as_json_schema
20
+ else
21
+ @options[:type].as_json_schema_without_links
22
+ end
23
+ else
24
+ {
25
+ description: description,
26
+ example: example,
27
+ format: format_type,
28
+ items: items_as_json_schema,
29
+ pattern: pattern_in_string,
30
+ properties: properties_as_json_schema,
31
+ required: required_property_names,
32
+ type: type,
33
+ uniqueItems: unique_flag,
34
+ }.reject do |_key, value|
35
+ value.nil? || value.respond_to?(:empty?) && value.empty?
36
+ end
29
37
  end
30
38
  end
31
39
 
@@ -59,6 +67,11 @@ module JsonWorld
59
67
  end
60
68
  end
61
69
 
70
+ # @return [false, true]
71
+ def has_json_schema_compatible_type?
72
+ @options[:type].respond_to?(:as_json_schema)
73
+ end
74
+
62
75
  # @note Tuple validation is not supported yet
63
76
  # @return [Array<Hash>, nil]
64
77
  def items_as_json_schema
@@ -1,3 +1,3 @@
1
1
  module JsonWorld
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.2.2
125
+ rubygems_version: 2.4.5
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Provides DSL to define JSON Schema representation of your class.