apiwork 0.7.1 → 0.7.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/app/controllers/apiwork/exports_controller.rb +0 -2
- data/lib/apiwork/adapter/base.rb +10 -2
- data/lib/apiwork/adapter/capability/base.rb +2 -0
- data/lib/apiwork/adapter/capability/contract/scope.rb +0 -1
- data/lib/apiwork/adapter/capability/operation/base.rb +1 -0
- data/lib/apiwork/adapter/capability/runner.rb +0 -1
- data/lib/apiwork/adapter/serializer/resource/base.rb +0 -1
- data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +1 -2
- data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +0 -3
- data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +0 -16
- data/lib/apiwork/adapter/standard/capability/filtering.rb +3 -0
- data/lib/apiwork/adapter/standard/capability/including/operation.rb +0 -1
- data/lib/apiwork/adapter/standard/capability/including.rb +1 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +0 -1
- data/lib/apiwork/adapter/standard/capability/pagination.rb +2 -0
- data/lib/apiwork/adapter/standard/capability/sorting.rb +2 -0
- data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +0 -4
- data/lib/apiwork/adapter/standard/capability/writing/operation.rb +1 -0
- data/lib/apiwork/adapter/standard/capability/writing.rb +2 -0
- data/lib/apiwork/adapter/standard.rb +3 -0
- data/lib/apiwork/adapter/wrapper/collection/default.rb +1 -0
- data/lib/apiwork/adapter/wrapper/member/default.rb +2 -0
- data/lib/apiwork/api/base.rb +5 -7
- data/lib/apiwork/api/object.rb +1 -1
- data/lib/apiwork/api/resource.rb +10 -10
- data/lib/apiwork/api/router.rb +0 -1
- data/lib/apiwork/api/type_registry.rb +1 -0
- data/lib/apiwork/configuration/option.rb +0 -1
- data/lib/apiwork/configuration/validatable.rb +1 -0
- data/lib/apiwork/configuration.rb +1 -0
- data/lib/apiwork/contract/action/request.rb +4 -0
- data/lib/apiwork/contract/action/response.rb +1 -0
- data/lib/apiwork/contract/action.rb +2 -2
- data/lib/apiwork/contract/base.rb +3 -3
- data/lib/apiwork/contract/object/coercer.rb +0 -2
- data/lib/apiwork/contract/object/deserializer.rb +0 -1
- data/lib/apiwork/contract/object/transformer.rb +0 -1
- data/lib/apiwork/contract/object/validator.rb +12 -18
- data/lib/apiwork/contract/object.rb +7 -9
- data/lib/apiwork/contract/request_parser.rb +0 -2
- data/lib/apiwork/controller.rb +3 -6
- data/lib/apiwork/engine.rb +1 -0
- data/lib/apiwork/error_code/registry.rb +0 -1
- data/lib/apiwork/export/apiwork.rb +1 -0
- data/lib/apiwork/export/apiwork_mapper.rb +0 -1
- data/lib/apiwork/export/base.rb +2 -3
- data/lib/apiwork/export/open_api.rb +4 -11
- data/lib/apiwork/export/pipeline/writer.rb +1 -1
- data/lib/apiwork/export/pipeline.rb +0 -5
- data/lib/apiwork/export/sorbus.rb +2 -0
- data/lib/apiwork/export/sorbus_mapper.rb +1 -5
- data/lib/apiwork/export/surface_resolver.rb +6 -4
- data/lib/apiwork/export/type_analysis.rb +2 -1
- data/lib/apiwork/export/type_script.rb +2 -0
- data/lib/apiwork/export/type_script_mapper.rb +0 -8
- data/lib/apiwork/export/zod.rb +4 -2
- data/lib/apiwork/export/zod_mapper.rb +0 -8
- data/lib/apiwork/introspection/dump/action.rb +1 -1
- data/lib/apiwork/introspection/dump/api.rb +0 -4
- data/lib/apiwork/introspection/dump/contract.rb +0 -6
- data/lib/apiwork/introspection/dump/param.rb +6 -6
- data/lib/apiwork/introspection/dump/resource.rb +1 -0
- data/lib/apiwork/introspection/dump/type.rb +5 -5
- data/lib/apiwork/reference_generator.rb +10 -10
- data/lib/apiwork/registry.rb +1 -0
- data/lib/apiwork/representation/association.rb +3 -3
- data/lib/apiwork/representation/attribute.rb +0 -4
- data/lib/apiwork/representation/base.rb +2 -5
- data/lib/apiwork/representation/deserializer.rb +0 -1
- data/lib/apiwork/representation/inheritance.rb +22 -10
- data/lib/apiwork/representation/model_detector.rb +1 -0
- data/lib/apiwork/representation/serializer.rb +3 -2
- data/lib/apiwork/version.rb +1 -1
- data/lib/apiwork.rb +9 -8
- metadata +4 -4
|
@@ -170,7 +170,6 @@ module Apiwork
|
|
|
170
170
|
optional = false if optional.nil?
|
|
171
171
|
nullable = false if nullable.nil?
|
|
172
172
|
default = '' if UNSET.equal?(default) && empty
|
|
173
|
-
|
|
174
173
|
@filterable = filterable
|
|
175
174
|
@preload = preload
|
|
176
175
|
@sortable = sortable
|
|
@@ -191,7 +190,6 @@ module Apiwork
|
|
|
191
190
|
@write_only = write_only
|
|
192
191
|
@default_set = !UNSET.equal?(default)
|
|
193
192
|
@default = @default_set ? default : nil
|
|
194
|
-
|
|
195
193
|
validate_min_max_range!
|
|
196
194
|
validate_format!
|
|
197
195
|
validate_empty!
|
|
@@ -350,7 +348,6 @@ module Apiwork
|
|
|
350
348
|
|
|
351
349
|
column = column_for(name)
|
|
352
350
|
return false unless column
|
|
353
|
-
|
|
354
351
|
return true unless column.default.nil?
|
|
355
352
|
|
|
356
353
|
column.null
|
|
@@ -366,7 +363,6 @@ module Apiwork
|
|
|
366
363
|
|
|
367
364
|
default = @model_class.column_defaults[name.to_s]
|
|
368
365
|
return default unless default.nil?
|
|
369
|
-
|
|
370
366
|
return '' if empty && nullable && optional
|
|
371
367
|
return nil if nullable && optional
|
|
372
368
|
|
|
@@ -67,7 +67,6 @@ module Apiwork
|
|
|
67
67
|
#
|
|
68
68
|
# @return [Representation::Inheritance, nil]
|
|
69
69
|
class_attribute :inheritance, default: nil, instance_accessor: false
|
|
70
|
-
|
|
71
70
|
class_attribute :_adapter_config, default: {}, instance_accessor: false
|
|
72
71
|
class_attribute :type_definitions, default: {}, instance_accessor: false
|
|
73
72
|
|
|
@@ -128,10 +127,12 @@ module Apiwork
|
|
|
128
127
|
"model must be an ActiveRecord model class, got #{value.class}. " \
|
|
129
128
|
"Use: model Post (not 'Post' or :post)"
|
|
130
129
|
end
|
|
130
|
+
|
|
131
131
|
unless value < ActiveRecord::Base
|
|
132
132
|
raise ConfigurationError,
|
|
133
133
|
"model must be an ActiveRecord model class, got #{value}"
|
|
134
134
|
end
|
|
135
|
+
|
|
135
136
|
@model_class = value
|
|
136
137
|
end
|
|
137
138
|
|
|
@@ -862,7 +863,6 @@ module Apiwork
|
|
|
862
863
|
target_class = subclass? ? superclass : self
|
|
863
864
|
target_inheritance = target_class.inheritance
|
|
864
865
|
target_model = target_class.model_class
|
|
865
|
-
|
|
866
866
|
return nil unless target_inheritance&.subclasses&.any?
|
|
867
867
|
return nil unless target_model.respond_to?(:inheritance_column)
|
|
868
868
|
|
|
@@ -872,7 +872,6 @@ module Apiwork
|
|
|
872
872
|
def serialize_record(record, context: {}, include: nil)
|
|
873
873
|
subclass_representation_class = inheritance.resolve(record) if inheritance&.subclasses&.any?
|
|
874
874
|
representation_class = subclass_representation_class || self
|
|
875
|
-
|
|
876
875
|
representation_class.new(record, context:, include:).as_json
|
|
877
876
|
end
|
|
878
877
|
|
|
@@ -896,9 +895,7 @@ module Apiwork
|
|
|
896
895
|
return unless @model_class
|
|
897
896
|
|
|
898
897
|
model_detector = ModelDetector.new(self)
|
|
899
|
-
|
|
900
898
|
auto_configure_inheritance if model_detector.sti_base?(@model_class) && inheritance.nil?
|
|
901
|
-
|
|
902
899
|
return unless model_detector.sti_subclass?(@model_class)
|
|
903
900
|
return unless model_detector.superclass_is_sti_base?(@model_class)
|
|
904
901
|
return if subclass?
|
|
@@ -18,13 +18,7 @@ module Apiwork
|
|
|
18
18
|
# The base class for this inheritance.
|
|
19
19
|
#
|
|
20
20
|
# @return [Class<Representation::Base>]
|
|
21
|
-
|
|
22
|
-
# @api public
|
|
23
|
-
# The subclasses for this inheritance.
|
|
24
|
-
#
|
|
25
|
-
# @return [Array<Class<Representation::Base>>]
|
|
26
|
-
attr_reader :base_class,
|
|
27
|
-
:subclasses
|
|
21
|
+
attr_reader :base_class
|
|
28
22
|
|
|
29
23
|
def initialize(base_class)
|
|
30
24
|
@base_class = base_class
|
|
@@ -47,7 +41,7 @@ module Apiwork
|
|
|
47
41
|
# @return [Class<Representation::Base>, nil]
|
|
48
42
|
def resolve(record)
|
|
49
43
|
type_value = record.public_send(column)
|
|
50
|
-
|
|
44
|
+
subclasses.find { |klass| klass.model_class.sti_name == type_value }
|
|
51
45
|
end
|
|
52
46
|
|
|
53
47
|
# @api public
|
|
@@ -55,7 +49,7 @@ module Apiwork
|
|
|
55
49
|
#
|
|
56
50
|
# @return [Boolean]
|
|
57
51
|
def transform?
|
|
58
|
-
|
|
52
|
+
subclasses.any? { |klass| klass.sti_name != klass.model_class.sti_name }
|
|
59
53
|
end
|
|
60
54
|
|
|
61
55
|
# @api public
|
|
@@ -63,16 +57,34 @@ module Apiwork
|
|
|
63
57
|
#
|
|
64
58
|
# @return [Hash{String => String}]
|
|
65
59
|
def mapping
|
|
66
|
-
|
|
60
|
+
subclasses.to_h { |klass| [klass.sti_name, klass.model_class.sti_name] }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @api public
|
|
64
|
+
# The subclasses for this inheritance.
|
|
65
|
+
#
|
|
66
|
+
# @return [Array<Class<Representation::Base>>]
|
|
67
|
+
def subclasses
|
|
68
|
+
Apiwork.eager_load_representations!
|
|
69
|
+
detect_subclasses
|
|
70
|
+
@subclasses
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
def register(representation_class)
|
|
70
74
|
@subclasses << representation_class
|
|
75
|
+
@subclasses.sort_by!(&:name)
|
|
71
76
|
end
|
|
72
77
|
|
|
73
78
|
def subclass?(representation_class)
|
|
79
|
+
detect_subclasses
|
|
74
80
|
@subclasses.include?(representation_class)
|
|
75
81
|
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def detect_subclasses
|
|
86
|
+
@base_class.subclasses.each(&:model_class)
|
|
87
|
+
end
|
|
76
88
|
end
|
|
77
89
|
end
|
|
78
90
|
end
|
|
@@ -17,7 +17,6 @@ module Apiwork
|
|
|
17
17
|
|
|
18
18
|
def serialize
|
|
19
19
|
fields = {}
|
|
20
|
-
|
|
21
20
|
add_discriminator_field(fields) if @representation_class.subclass?
|
|
22
21
|
|
|
23
22
|
@representation_class.attributes.each do |name, attribute|
|
|
@@ -51,12 +50,14 @@ module Apiwork
|
|
|
51
50
|
return value if value.nil?
|
|
52
51
|
|
|
53
52
|
association = @representation_class.polymorphic_association_for_type_column(attribute_name)
|
|
53
|
+
|
|
54
54
|
if association
|
|
55
55
|
found_class = association.find_representation_for_type(value)
|
|
56
56
|
return found_class.polymorphic_name if found_class
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
inheritance = @representation_class.inheritance_for_column(attribute_name)
|
|
60
|
+
|
|
60
61
|
if inheritance
|
|
61
62
|
klass = inheritance.subclasses.find { |subclass| subclass.model_class.sti_name == value }
|
|
62
63
|
return klass.sti_name if klass
|
|
@@ -85,8 +86,8 @@ module Apiwork
|
|
|
85
86
|
if target_representation_class.inheritance&.subclasses&.any?
|
|
86
87
|
subclass_representation_class = target_representation_class.inheritance.resolve(record)
|
|
87
88
|
end
|
|
88
|
-
representation_class = subclass_representation_class || target_representation_class
|
|
89
89
|
|
|
90
|
+
representation_class = subclass_representation_class || target_representation_class
|
|
90
91
|
representation_class.new(record, context: @representation.context, include: nested_includes).as_json
|
|
91
92
|
end
|
|
92
93
|
|
data/lib/apiwork/version.rb
CHANGED
data/lib/apiwork.rb
CHANGED
|
@@ -13,18 +13,23 @@ module Apiwork
|
|
|
13
13
|
routes.call(env)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def prepare!
|
|
16
|
+
def prepare!
|
|
17
17
|
API.clear!
|
|
18
18
|
Adapter.clear!
|
|
19
19
|
ErrorCode.clear!
|
|
20
20
|
Export.clear!
|
|
21
|
-
|
|
22
21
|
Adapter.register_defaults!
|
|
23
22
|
ErrorCode.register_defaults!
|
|
24
23
|
Export.register_defaults!
|
|
25
|
-
|
|
26
24
|
load_api_definitions!
|
|
27
|
-
|
|
25
|
+
@representations_eager_loaded = false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def eager_load_representations!
|
|
29
|
+
return if @representations_eager_loaded
|
|
30
|
+
|
|
31
|
+
Rails.autoloaders.main.eager_load_dir(Rails.root.join('app/representations'))
|
|
32
|
+
@representations_eager_loaded = true
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
private
|
|
@@ -39,10 +44,6 @@ module Apiwork
|
|
|
39
44
|
API::Router.draw
|
|
40
45
|
end
|
|
41
46
|
|
|
42
|
-
def eager_load_representations!
|
|
43
|
-
Dir[Rails.root.join('app/representations/**/*.rb')].sort.each(&method(:require_dependency))
|
|
44
|
-
end
|
|
45
|
-
|
|
46
47
|
def load_api_definitions!
|
|
47
48
|
Dir[Rails.root.join('config/apis/**/*.rb')].sort.each(&method(:load))
|
|
48
49
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: apiwork
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- skiftle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0.
|
|
89
|
+
version: '0.2'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0.
|
|
96
|
+
version: '0.2'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: sqlite3
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|