model_driven_api 3.1.6 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a72bb6cfea6d9f8e0fd4fff0643ee5f73c4c4434532092bd428c7b048c5f9b0
4
- data.tar.gz: 51c3691214427e0aaa6111cf00a9b476fdb4c91861ba1819a227ea859f924a2d
3
+ metadata.gz: 1272f499542ca137fd53edb4e8e0221021c9640a8d0f964fc41546c6d55e3873
4
+ data.tar.gz: 23c1b8dafdcf82ffdfcc68113568ee07e9bd9ee10efaaeb860be8459e09a1c2e
5
5
  SHA512:
6
- metadata.gz: af0ddbc93b40f315b170630facacb7357022880e560502c83f4e2f2e5ac4342ffb5eaece4be1e1e591d5f0fa6b0a447b1e49ecbd6f9bf2975ee15c2a4b5c8743
7
- data.tar.gz: f6318805dc382e2ce28494a74174d01bd53fb12749151a6ea5b21d4ea610dd23a9a4ac8c3dce09ff241c21202f8c3291694056917024781df012f39ac8e25460
6
+ metadata.gz: 53941a7154e66342de797d2350fffe085f74cc6ddafc75c4d15231e14d1628b1d03c6891ee74674e0a47f634550cfc4c01bb335f2b58b5b592da5b20c4b72559
7
+ data.tar.gz: 22289e5e28cdd414390d2019b9f48526d606eacbdc026c259f3c8444fcf039b712e5099062f0b811970ce3ba00d3803870c97541faa6b94e2c5c2662ee89e856
@@ -84,14 +84,36 @@ class Api::V2::InfoController < Api::V2::ApplicationController
84
84
  method_key.type.to_s
85
85
  end
86
86
 
87
+ def integer?(str)
88
+ true if Integer(str) rescue false
89
+ end
90
+
91
+ def number?(str)
92
+ true if Float(str) rescue false
93
+ end
94
+
95
+ def datetime?(str)
96
+ true if DateTime.parse(str) rescue false
97
+ end
98
+
87
99
  def create_properties_from_model(model, dsl, remove_reserved = false)
88
- JSON.parse(model.new.to_json(dsl)).keys.map do |k|
100
+ parsed_json = JSON.parse(model.new.to_json(dsl))
101
+ parsed_json.keys.map do |k|
89
102
  type = compute_type(model, k)
90
103
 
91
104
  # Remove fields that cannot be created or updated
92
105
  if remove_reserved && %w( id created_at updated_at lock_version).include?(k.to_s)
93
106
  nil
107
+ elsif type == "method" && (parsed_json[k].is_a?(FalseClass) || parsed_json[k].is_a?(TrueClass))
108
+ [k, { "type": "boolean" }]
109
+ elsif type == "method" && parsed_json[k].is_a?(String) && number?(parsed_json[k])
110
+ [k, { "type": "number" }]
111
+ elsif type == "method" && parsed_json[k].is_a?(String) && integer?(parsed_json[k])
112
+ [k, { "type": "integer" }]
113
+ elsif type == "method" && parsed_json[k].is_a?(String) && datetime?(parsed_json[k])
114
+ [k, { "type": "string", "format": "date-time" }]
94
115
  elsif type == "method"
116
+ # Unknown or complex format returned
95
117
  [k, { "type": "object", "additionalProperties": true }]
96
118
  elsif type == "date"
97
119
  [k, { "type": "string", "format": "date" }]
@@ -422,7 +444,7 @@ class Api::V2::InfoController < Api::V2::ApplicationController
422
444
  }
423
445
  }
424
446
  }
425
- ApplicationRecord.subclasses.each do |d|
447
+ ApplicationRecord.subclasses.sort_by { |d| d.to_s }.each do |d|
426
448
  # Only if current user can read the model
427
449
  if true # can? :read, d
428
450
  model = d.to_s.underscore.tableize
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.1.6".freeze
2
+ VERSION = "3.1.7".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni