standardapi 7.1.1 → 7.1.2
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 +4 -4
- data/lib/standard_api/version.rb +1 -1
- data/lib/standard_api/views/application/_schema.json.jbuilder +11 -1
- data/lib/standard_api/views/application/_schema.streamer +10 -0
- data/lib/standard_api/visitors/validations.rb +60 -0
- data/lib/standard_api.rb +1 -0
- data/test/standard_api/standard_api_test.rb +23 -0
- data/test/standard_api/test_app/app/controllers/acl/property_acl.rb +13 -2
- data/test/standard_api/test_app/models.rb +17 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb9fe722c9847c5c2aa696b36fdbebbc4783f78d92036683b03cde0929f7b78a
|
4
|
+
data.tar.gz: 6723597440138d500614b84f34106279778addc18bd40419d854b0e7bbb628cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa742b8fda2329a7c17b314ac2b40c8ae46b139fa482516166e7c19a96e851c8438062a89b9de114a5425eaa429c69327faf1fb01b5b4e7e78f1415646a5669
|
7
|
+
data.tar.gz: 8f17ce9c37b5948c726e8cc13166acf8f5be4b7b63103d8c7eb55f308abfe65a6688000ac8b58a062bd30d8d385225a17ae9e8e80d34e8c757634084cab4776a
|
data/lib/standard_api/version.rb
CHANGED
@@ -69,7 +69,17 @@ else
|
|
69
69
|
# TODO: it would be nice if rails responded with a true or false here
|
70
70
|
# instead of the function itself
|
71
71
|
json.set! 'auto_populated', !!column.auto_populated? if column.respond_to?(:auto_populated?)
|
72
|
-
|
72
|
+
|
73
|
+
json.set! 'readonly', (if controller.respond_to?("#{ model.model_name.singular }_attributes")
|
74
|
+
!controller.send("#{ model.model_name.singular }_attributes").include?(column.name)
|
75
|
+
else
|
76
|
+
model.readonly_attribute?(column.name)
|
77
|
+
end)
|
78
|
+
|
79
|
+
visitor = StandardAPI::Visitors::Validator.new
|
80
|
+
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }
|
81
|
+
json.set! 'validations', validations
|
82
|
+
end
|
73
83
|
end
|
74
84
|
end
|
75
85
|
|
@@ -79,6 +79,16 @@ else
|
|
79
79
|
# TODO: it would be nice if rails responded with a true or false here
|
80
80
|
# instead of the function itself
|
81
81
|
json.set! 'auto_populated', !!column.auto_populated? if column.respond_to?(:auto_populated?)
|
82
|
+
|
83
|
+
json.set! 'readonly', (if controller.respond_to?("#{ model.model_name.singular }_attributes")
|
84
|
+
!controller.send("#{ model.model_name.singular }_attributes").include?(column.name)
|
85
|
+
else
|
86
|
+
true
|
87
|
+
end)
|
88
|
+
|
89
|
+
visitor = StandardAPI::Visitors::Validator.new
|
90
|
+
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }
|
91
|
+
json.set! 'validations', validations
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module StandardAPI
|
2
|
+
module Visitors
|
3
|
+
|
4
|
+
class Validator < Arel::Visitors::Visitor
|
5
|
+
|
6
|
+
def visit_ActiveRecord_Validations_AbsenceValidator(o, col)
|
7
|
+
visit_validator(:absence, o.options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def visit_ActiveRecord_Validations_AcceptanceValidator(o, col)
|
11
|
+
visit_validator(:acceptance, o.options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def visit_ActiveRecord_Validations_ComparisonValidator(o, col)
|
15
|
+
visit_validator(:comparison, o.options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def visit_ActiveRecord_Validations_ConfirmationValidator(o, col)
|
19
|
+
visit_validator(:confirmation, o.options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def visit_ActiveRecord_Validations_ExclusionValidator(o, col)
|
23
|
+
visit_validator(:exclusion, o.options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def visit_ActiveRecord_Validations_FormatValidator(o, col)
|
27
|
+
visit_validator(:format, o.options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def visit_ActiveRecord_Validations_InclusionValidator(o, col)
|
31
|
+
visit_validator(:inclusion, o.options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def visit_ActiveRecord_Validations_LengthValidator(o, col)
|
35
|
+
visit_validator(:length, o.options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def visit_ActiveRecord_Validations_NumericalityValidator(o, col)
|
39
|
+
visit_validator(:numericality, o.options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def visit_ActiveRecord_Validations_PresenceValidator(o, col)
|
43
|
+
visit_validator(:presence, o.options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def visit_ActiveRecord_Validations_WithValidator(o, col)
|
47
|
+
visit_validator(:with, o.options)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def visit_validator(name, options)
|
53
|
+
{ name => options.empty? ? true : options.as_json }
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/standard_api.rb
CHANGED
@@ -16,6 +16,7 @@ require 'standard_api/helpers'
|
|
16
16
|
require 'standard_api/route_helpers'
|
17
17
|
require 'standard_api/active_record/connection_adapters/postgresql/schema_statements'
|
18
18
|
require 'standard_api/railtie'
|
19
|
+
require 'standard_api/visitors/validations'
|
19
20
|
|
20
21
|
module StandardAPI
|
21
22
|
autoload :AccessControlList, 'standard_api/access_control_list'
|
@@ -161,6 +161,27 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
assert_equal true, schema['models']['Account']['attributes']['id']['readonly']
|
165
|
+
assert_equal false, schema['models']['Account']['attributes']['name']['readonly']
|
166
|
+
|
167
|
+
assert_equal [
|
168
|
+
{ "presence" => true }
|
169
|
+
], schema['models']['Property']['attributes']['name']['validations']
|
170
|
+
|
171
|
+
assert_equal [
|
172
|
+
{ "numericality" => {
|
173
|
+
"greater_than" => 1,
|
174
|
+
"greater_than_or_equal_to" => 2,
|
175
|
+
"equal_to" => 2,
|
176
|
+
"less_than_or_equal_to" => 2,
|
177
|
+
"less_than" => 3,
|
178
|
+
"other_than" => 0,
|
179
|
+
"even" => true,
|
180
|
+
"in" => "1..3"
|
181
|
+
}
|
182
|
+
}
|
183
|
+
], schema['models']['Property']['attributes']['numericality']['validations']
|
184
|
+
|
164
185
|
assert_equal 'test comment', schema['comment']
|
165
186
|
end
|
166
187
|
|
@@ -756,4 +777,6 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|
756
777
|
end
|
757
778
|
end
|
758
779
|
|
780
|
+
|
781
|
+
|
759
782
|
end
|
@@ -7,7 +7,8 @@ module PropertyACL
|
|
7
7
|
:description,
|
8
8
|
:constructed,
|
9
9
|
:size,
|
10
|
-
:active
|
10
|
+
:active,
|
11
|
+
:numericality
|
11
12
|
# :photos_attributes,
|
12
13
|
# { photos_attributes: [ :id, :account_id, :property_id, :format] }
|
13
14
|
]
|
@@ -15,7 +16,17 @@ module PropertyACL
|
|
15
16
|
|
16
17
|
# Orderings allowed
|
17
18
|
def orders
|
18
|
-
[
|
19
|
+
[
|
20
|
+
"id",
|
21
|
+
"name",
|
22
|
+
"aliases",
|
23
|
+
"description",
|
24
|
+
"constructed",
|
25
|
+
"size",
|
26
|
+
"created_at",
|
27
|
+
"active",
|
28
|
+
"numericality"
|
29
|
+
]
|
19
30
|
end
|
20
31
|
|
21
32
|
# Sub resources allowed to be included in the response
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
|
15
15
|
class Document < ActiveRecord::Base
|
16
16
|
attr_accessor :file
|
17
|
-
|
17
|
+
|
18
18
|
enum level: { public: 0, secret: 1 }, _suffix: true
|
19
19
|
enum rating: { poor: 0, ok: 1, good: 2 }
|
20
20
|
end
|
@@ -29,13 +29,25 @@ class Property < ActiveRecord::Base
|
|
29
29
|
has_one :document_attachments, class_name: "Attachment", as: :record, inverse_of: :record
|
30
30
|
has_one :document, through: "document_attachments"
|
31
31
|
|
32
|
-
|
33
32
|
validates :name, presence: true
|
34
33
|
accepts_nested_attributes_for :photos
|
35
34
|
|
36
35
|
def english_name
|
37
36
|
'A Name'
|
38
37
|
end
|
38
|
+
|
39
|
+
# Numericality Validation
|
40
|
+
validates :numericality, numericality: {
|
41
|
+
greater_than: 1,
|
42
|
+
greater_than_or_equal_to: 2,
|
43
|
+
equal_to: 2,
|
44
|
+
less_than_or_equal_to: 2,
|
45
|
+
less_than: 3,
|
46
|
+
other_than: 0,
|
47
|
+
even: true,
|
48
|
+
in: 1..3
|
49
|
+
}
|
50
|
+
|
39
51
|
end
|
40
52
|
|
41
53
|
class LSNType < ActiveRecord::Type::Value
|
@@ -129,6 +141,7 @@ class CreateModelTables < ActiveRecord::Migration[6.0]
|
|
129
141
|
t.decimal "size"
|
130
142
|
t.datetime "created_at", null: false
|
131
143
|
t.boolean "active", default: false
|
144
|
+
t.integer "numericality", default: 2
|
132
145
|
end
|
133
146
|
|
134
147
|
create_table "references", force: :cascade do |t|
|
@@ -167,12 +180,12 @@ class CreateModelTables < ActiveRecord::Migration[6.0]
|
|
167
180
|
t.integer 'record_id'
|
168
181
|
t.integer 'document_id'
|
169
182
|
end
|
170
|
-
|
183
|
+
|
171
184
|
create_table "uuid_models", id: :uuid, force: :cascade do |t|
|
172
185
|
t.string 'title', default: 'recruit'
|
173
186
|
t.string 'name', default: -> { 'round(random() * 1000)' }
|
174
187
|
end
|
175
|
-
|
188
|
+
|
176
189
|
end
|
177
190
|
|
178
191
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standardapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -306,6 +306,7 @@ files:
|
|
306
306
|
- lib/standard_api/views/application/schema.streamer
|
307
307
|
- lib/standard_api/views/application/show.json.jbuilder
|
308
308
|
- lib/standard_api/views/application/show.streamer
|
309
|
+
- lib/standard_api/visitors/validations.rb
|
309
310
|
- test/standard_api/caching_test.rb
|
310
311
|
- test/standard_api/controller/include_test.rb
|
311
312
|
- test/standard_api/controller/subresource_test.rb
|
@@ -361,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
361
362
|
- !ruby/object:Gem::Version
|
362
363
|
version: '0'
|
363
364
|
requirements: []
|
364
|
-
rubygems_version: 3.5.
|
365
|
+
rubygems_version: 3.5.15
|
365
366
|
signing_key:
|
366
367
|
specification_version: 4
|
367
368
|
summary: StandardAPI makes it easy to expose a query interface for your Rails models
|