model_driven_api 3.1.5 → 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 +33 -9
- 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,12 +84,36 @@ class Api::V2::InfoController < Api::V2::ApplicationController
|
|
84
84
|
method_key.type.to_s
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
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
|
+
|
99
|
+
def create_properties_from_model(model, dsl, remove_reserved = false)
|
100
|
+
parsed_json = JSON.parse(model.new.to_json(dsl))
|
101
|
+
parsed_json.keys.map do |k|
|
90
102
|
type = compute_type(model, k)
|
91
|
-
|
92
|
-
|
103
|
+
|
104
|
+
# Remove fields that cannot be created or updated
|
105
|
+
if remove_reserved && %w( id created_at updated_at lock_version).include?(k.to_s)
|
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" }]
|
115
|
+
elsif type == "method"
|
116
|
+
# Unknown or complex format returned
|
93
117
|
[k, { "type": "object", "additionalProperties": true }]
|
94
118
|
elsif type == "date"
|
95
119
|
[k, { "type": "string", "format": "date" }]
|
@@ -420,7 +444,7 @@ class Api::V2::InfoController < Api::V2::ApplicationController
|
|
420
444
|
}
|
421
445
|
}
|
422
446
|
}
|
423
|
-
ApplicationRecord.subclasses.each do |d|
|
447
|
+
ApplicationRecord.subclasses.sort_by { |d| d.to_s }.each do |d|
|
424
448
|
# Only if current user can read the model
|
425
449
|
if true # can? :read, d
|
426
450
|
model = d.to_s.underscore.tableize
|
@@ -468,7 +492,7 @@ class Api::V2::InfoController < Api::V2::ApplicationController
|
|
468
492
|
"properties": {
|
469
493
|
"#{model.singularize}": {
|
470
494
|
"type": "object",
|
471
|
-
"properties": create_properties_from_model(d, {})
|
495
|
+
"properties": create_properties_from_model(d, {}, true)
|
472
496
|
}
|
473
497
|
}
|
474
498
|
}
|
@@ -611,7 +635,7 @@ class Api::V2::InfoController < Api::V2::ApplicationController
|
|
611
635
|
"properties": {
|
612
636
|
"#{model.singularize}": {
|
613
637
|
"type": "object",
|
614
|
-
"properties": create_properties_from_model(d, {})
|
638
|
+
"properties": create_properties_from_model(d, {}, true)
|
615
639
|
}
|
616
640
|
}
|
617
641
|
}
|
@@ -660,7 +684,7 @@ class Api::V2::InfoController < Api::V2::ApplicationController
|
|
660
684
|
"properties": {
|
661
685
|
"#{model.singularize}": {
|
662
686
|
"type": "object",
|
663
|
-
"properties": create_properties_from_model(d, {})
|
687
|
+
"properties": create_properties_from_model(d, {}, true)
|
664
688
|
}
|
665
689
|
}
|
666
690
|
}
|