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 +4 -4
- data/app/controllers/api/v2/info_controller.rb +24 -2
- data/lib/model_driven_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1272f499542ca137fd53edb4e8e0221021c9640a8d0f964fc41546c6d55e3873
|
4
|
+
data.tar.gz: 23c1b8dafdcf82ffdfcc68113568ee07e9bd9ee10efaaeb860be8459e09a1c2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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))
|
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
|