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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/apiwork/exports_controller.rb +0 -2
  3. data/lib/apiwork/adapter/base.rb +10 -2
  4. data/lib/apiwork/adapter/capability/base.rb +2 -0
  5. data/lib/apiwork/adapter/capability/contract/scope.rb +0 -1
  6. data/lib/apiwork/adapter/capability/operation/base.rb +1 -0
  7. data/lib/apiwork/adapter/capability/runner.rb +0 -1
  8. data/lib/apiwork/adapter/serializer/resource/base.rb +0 -1
  9. data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +1 -2
  10. data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +0 -3
  11. data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +0 -16
  12. data/lib/apiwork/adapter/standard/capability/filtering.rb +3 -0
  13. data/lib/apiwork/adapter/standard/capability/including/operation.rb +0 -1
  14. data/lib/apiwork/adapter/standard/capability/including.rb +1 -0
  15. data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +0 -1
  16. data/lib/apiwork/adapter/standard/capability/pagination.rb +2 -0
  17. data/lib/apiwork/adapter/standard/capability/sorting.rb +2 -0
  18. data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +0 -4
  19. data/lib/apiwork/adapter/standard/capability/writing/operation.rb +1 -0
  20. data/lib/apiwork/adapter/standard/capability/writing.rb +2 -0
  21. data/lib/apiwork/adapter/standard.rb +3 -0
  22. data/lib/apiwork/adapter/wrapper/collection/default.rb +1 -0
  23. data/lib/apiwork/adapter/wrapper/member/default.rb +2 -0
  24. data/lib/apiwork/api/base.rb +5 -7
  25. data/lib/apiwork/api/object.rb +1 -1
  26. data/lib/apiwork/api/resource.rb +10 -10
  27. data/lib/apiwork/api/router.rb +0 -1
  28. data/lib/apiwork/api/type_registry.rb +1 -0
  29. data/lib/apiwork/configuration/option.rb +0 -1
  30. data/lib/apiwork/configuration/validatable.rb +1 -0
  31. data/lib/apiwork/configuration.rb +1 -0
  32. data/lib/apiwork/contract/action/request.rb +4 -0
  33. data/lib/apiwork/contract/action/response.rb +1 -0
  34. data/lib/apiwork/contract/action.rb +2 -2
  35. data/lib/apiwork/contract/base.rb +3 -3
  36. data/lib/apiwork/contract/object/coercer.rb +0 -2
  37. data/lib/apiwork/contract/object/deserializer.rb +0 -1
  38. data/lib/apiwork/contract/object/transformer.rb +0 -1
  39. data/lib/apiwork/contract/object/validator.rb +12 -18
  40. data/lib/apiwork/contract/object.rb +7 -9
  41. data/lib/apiwork/contract/request_parser.rb +0 -2
  42. data/lib/apiwork/controller.rb +3 -6
  43. data/lib/apiwork/engine.rb +1 -0
  44. data/lib/apiwork/error_code/registry.rb +0 -1
  45. data/lib/apiwork/export/apiwork.rb +1 -0
  46. data/lib/apiwork/export/apiwork_mapper.rb +0 -1
  47. data/lib/apiwork/export/base.rb +2 -3
  48. data/lib/apiwork/export/open_api.rb +4 -11
  49. data/lib/apiwork/export/pipeline/writer.rb +1 -1
  50. data/lib/apiwork/export/pipeline.rb +0 -5
  51. data/lib/apiwork/export/sorbus.rb +2 -0
  52. data/lib/apiwork/export/sorbus_mapper.rb +1 -5
  53. data/lib/apiwork/export/surface_resolver.rb +6 -4
  54. data/lib/apiwork/export/type_analysis.rb +2 -1
  55. data/lib/apiwork/export/type_script.rb +2 -0
  56. data/lib/apiwork/export/type_script_mapper.rb +0 -8
  57. data/lib/apiwork/export/zod.rb +4 -2
  58. data/lib/apiwork/export/zod_mapper.rb +0 -8
  59. data/lib/apiwork/introspection/dump/action.rb +1 -1
  60. data/lib/apiwork/introspection/dump/api.rb +0 -4
  61. data/lib/apiwork/introspection/dump/contract.rb +0 -6
  62. data/lib/apiwork/introspection/dump/param.rb +6 -6
  63. data/lib/apiwork/introspection/dump/resource.rb +1 -0
  64. data/lib/apiwork/introspection/dump/type.rb +5 -5
  65. data/lib/apiwork/reference_generator.rb +10 -10
  66. data/lib/apiwork/registry.rb +1 -0
  67. data/lib/apiwork/representation/association.rb +3 -3
  68. data/lib/apiwork/representation/attribute.rb +0 -4
  69. data/lib/apiwork/representation/base.rb +2 -5
  70. data/lib/apiwork/representation/deserializer.rb +0 -1
  71. data/lib/apiwork/representation/inheritance.rb +22 -10
  72. data/lib/apiwork/representation/model_detector.rb +1 -0
  73. data/lib/apiwork/representation/serializer.rb +3 -2
  74. data/lib/apiwork/version.rb +1 -1
  75. data/lib/apiwork.rb +9 -8
  76. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5949ff5143ec3bdd3c0349b639eb17306ce00d32c6567a618bdd1f8f3474d9fc
4
- data.tar.gz: 3d8e835b75f3c85725e17459ae24c6b6154002b7733f76315826a776799a9860
3
+ metadata.gz: ffc0d344ecd8ffd9db4568c2c57bff2d1c6770339045bbbc6b48ea3c14304688
4
+ data.tar.gz: ab453fab98baf8460e981af69fa1693f2538d85d9929a870f0427035e0a27ab5
5
5
  SHA512:
6
- metadata.gz: 93ac9cbc50161930b09f247309256590241180080a710c2e49621874a654a0d70d02888a9972ed342058047312371b5de9f47f0039f4f09525991e2a3ba252a7
7
- data.tar.gz: 757058cf4777c10627862c7dd4142473c76027f340042d636978a805c8adaa82e2c74963e366d168cb2140273e5e845bc3fba8bb9fe76d5d5f5a21d5ad9ce208
6
+ metadata.gz: 3f61e2986a8605b629450668fac8050630e86de75ec858384a41c24a334717c85aa80ab139f393d16fb1e109f98a719b7749ef39ee593896a8863ca4b963935d
7
+ data.tar.gz: 3751ed380242dcb30a4fba2fa990a000b093071e8d393dd533551a3089d4cc915190d1f9f638c8d29062d6125e67f2a770dcbc0d5c00e6917415924d6aabb16e
@@ -13,9 +13,7 @@ module Apiwork
13
13
 
14
14
  format = raw_options[:format]&.to_sym
15
15
  options = export_class.extract_options(raw_options)
16
-
17
16
  result = Export.generate(export_name, api_class.base_path, format:, **options)
18
-
19
17
  render content_type: export_class.content_type_for(format:), plain: result
20
18
  end
21
19
  end
@@ -57,7 +57,6 @@ module Apiwork
57
57
  def capability(klass)
58
58
  @capabilities ||= []
59
59
  @capabilities << klass
60
-
61
60
  return unless klass.options.any?
62
61
 
63
62
  name = klass.capability_name
@@ -99,6 +98,7 @@ module Apiwork
99
98
  validate_class_setter!(:resource_serializer, klass, Serializer::Resource::Base, 'Serializer')
100
99
  @resource_serializer = klass
101
100
  end
101
+
102
102
  @resource_serializer || (superclass.respond_to?(:resource_serializer) && superclass.resource_serializer)
103
103
  end
104
104
 
@@ -116,6 +116,7 @@ module Apiwork
116
116
  validate_class_setter!(:error_serializer, klass, Serializer::Error::Base, 'Serializer')
117
117
  @error_serializer = klass
118
118
  end
119
+
119
120
  @error_serializer || (superclass.respond_to?(:error_serializer) && superclass.error_serializer)
120
121
  end
121
122
 
@@ -133,6 +134,7 @@ module Apiwork
133
134
  validate_class_setter!(:member_wrapper, klass, Wrapper::Member::Base, 'Wrapper')
134
135
  @member_wrapper = klass
135
136
  end
137
+
136
138
  @member_wrapper || (superclass.respond_to?(:member_wrapper) && superclass.member_wrapper)
137
139
  end
138
140
 
@@ -150,6 +152,7 @@ module Apiwork
150
152
  validate_class_setter!(:collection_wrapper, klass, Wrapper::Collection::Base, 'Wrapper')
151
153
  @collection_wrapper = klass
152
154
  end
155
+
153
156
  @collection_wrapper || (superclass.respond_to?(:collection_wrapper) && superclass.collection_wrapper)
154
157
  end
155
158
 
@@ -167,6 +170,7 @@ module Apiwork
167
170
  validate_class_setter!(:error_wrapper, klass, Wrapper::Error::Base, 'Wrapper')
168
171
  @error_wrapper = klass
169
172
  end
173
+
170
174
  @error_wrapper || (superclass.respond_to?(:error_wrapper) && superclass.error_wrapper)
171
175
  end
172
176
 
@@ -178,6 +182,7 @@ module Apiwork
178
182
  "#{name} must be a #{label} class, got #{klass.class}. " \
179
183
  "Use: #{name} Example (not 'Example' or :example)"
180
184
  end
185
+
181
186
  return if klass < base_class
182
187
 
183
188
  raise ConfigurationError,
@@ -198,6 +203,10 @@ module Apiwork
198
203
  self.class.member_wrapper.wrap(data, metadata, representation_class.root_key, meta)
199
204
  end
200
205
 
206
+ def process_no_content(data, representation_class, request)
207
+ apply_capabilities(data, representation_class, request, wrapper_type: :member)
208
+ end
209
+
201
210
  def process_error(error, representation_class, context: {})
202
211
  data = self.class.error_serializer.serialize(error, context:)
203
212
  self.class.error_wrapper.wrap(data)
@@ -218,7 +227,6 @@ module Apiwork
218
227
  end
219
228
 
220
229
  self.class.resource_serializer.new(representation_class).contract_types(contract_class)
221
-
222
230
  build_action_responses(contract_class, representation_class, resource_actions) if resource_actions.any?
223
231
  end
224
232
 
@@ -226,12 +226,14 @@ module Apiwork
226
226
  return nil if object.params.empty?
227
227
 
228
228
  type_name = resolve_metadata_type_name(representation_class)
229
+
229
230
  register_metadata_fragment(
230
231
  representation_class.api_class,
231
232
  type_name,
232
233
  metadata_shape_class,
233
234
  merged_config(representation_class),
234
235
  )
236
+
235
237
  type_name
236
238
  end
237
239
 
@@ -15,7 +15,6 @@ module Apiwork
15
15
  #
16
16
  # @return [Hash{Symbol => Resource::Action}]
17
17
  attr_reader :actions
18
-
19
18
  attr_reader :representation_class
20
19
 
21
20
  def initialize(representation_class, actions)
@@ -72,6 +72,7 @@ module Apiwork
72
72
  elsif block
73
73
  @metadata_shape_class = wrap_metadata_shape_block(block)
74
74
  end
75
+
75
76
  @metadata_shape_class
76
77
  end
77
78
 
@@ -32,7 +32,6 @@ module Apiwork
32
32
 
33
33
  includes.concat(representation_class.preloads)
34
34
  preloaded = preload_associations(result_data, includes.flatten.compact)
35
-
36
35
  [preloaded, metadata, serialize_options]
37
36
  end
38
37
 
@@ -59,7 +59,6 @@ module Apiwork
59
59
 
60
60
  def contract_types(contract_class)
61
61
  register_representation_types(contract_class)
62
-
63
62
  builder_class = self.class.contract_builder
64
63
  return unless builder_class
65
64
 
@@ -44,6 +44,7 @@ module Apiwork
44
44
 
45
45
  def register_type(type_name)
46
46
  association_type_map = {}
47
+
47
48
  representation_class.associations.each do |name, association|
48
49
  association_type_map[name] = build_association_type(association)
49
50
  end
@@ -160,7 +161,6 @@ module Apiwork
160
161
  return nil unless association_info
161
162
 
162
163
  representation_class = association_info[:representation_class]
163
-
164
164
  return import_association_contract(representation_class, visited) if association_info[:sti]
165
165
  return nil if visited.include?(representation_class)
166
166
 
@@ -177,7 +177,6 @@ module Apiwork
177
177
  return nil unless polymorphic.any?
178
178
 
179
179
  union_type_name = association.name
180
-
181
180
  existing_type = type?(union_type_name)
182
181
  return union_type_name if existing_type
183
182
 
@@ -10,20 +10,17 @@ module Apiwork
10
10
  OR = :OR
11
11
  NOT = :NOT
12
12
  LOGICAL_OPERATORS = [AND, OR, NOT].freeze
13
-
14
13
  EQUALITY_OPERATORS = %i[eq].freeze
15
14
  COMPARISON_OPERATORS = %i[gt gte lt lte].freeze
16
15
  RANGE_OPERATORS = %i[between].freeze
17
16
  COLLECTION_OPERATORS = %i[in].freeze
18
17
  STRING_SPECIFIC_OPERATORS = %i[contains starts_with ends_with].freeze
19
18
  NULL_OPERATORS = %i[null].freeze
20
-
21
19
  STRING_OPERATORS = (EQUALITY_OPERATORS + COLLECTION_OPERATORS + STRING_SPECIFIC_OPERATORS).freeze
22
20
  DATE_OPERATORS = (EQUALITY_OPERATORS + COMPARISON_OPERATORS + RANGE_OPERATORS + COLLECTION_OPERATORS).freeze
23
21
  NUMERIC_OPERATORS = (EQUALITY_OPERATORS + COMPARISON_OPERATORS + RANGE_OPERATORS + COLLECTION_OPERATORS).freeze
24
22
  UUID_OPERATORS = (EQUALITY_OPERATORS + COLLECTION_OPERATORS).freeze
25
23
  BOOLEAN_OPERATORS = EQUALITY_OPERATORS.freeze
26
-
27
24
  NULLABLE_STRING_OPERATORS = (STRING_OPERATORS + NULL_OPERATORS).freeze
28
25
  NULLABLE_DATE_OPERATORS = (DATE_OPERATORS + NULL_OPERATORS).freeze
29
26
  NULLABLE_NUMERIC_OPERATORS = (NUMERIC_OPERATORS + NULL_OPERATORS).freeze
@@ -60,7 +60,6 @@ module Apiwork
60
60
 
61
61
  def apply_hash_filter(params)
62
62
  logical_operators, regular_attributes = separate_logical_operators(params)
63
-
64
63
  scope = @relation
65
64
 
66
65
  if regular_attributes.present?
@@ -71,7 +70,6 @@ module Apiwork
71
70
  scope = apply_not(scope, logical_operators[Constants::NOT]) if logical_operators.key?(Constants::NOT)
72
71
  scope = apply_or(scope, logical_operators[Constants::OR]) if logical_operators.key?(Constants::OR)
73
72
  scope = apply_and(scope, logical_operators[Constants::AND]) if logical_operators.key?(Constants::AND)
74
-
75
73
  scope
76
74
  end
77
75
 
@@ -137,7 +135,6 @@ module Apiwork
137
135
  return [nil, {}] unless filter_params.is_a?(Hash)
138
136
 
139
137
  logical_operators, regular_attributes = separate_logical_operators(filter_params)
140
-
141
138
  conditions = []
142
139
  all_joins = {}
143
140
 
@@ -190,10 +187,8 @@ module Apiwork
190
187
  def build_column_condition(key, value, target_klass)
191
188
  association = representation_class.polymorphic_association_for_type_column(key)
192
189
  value = transform_polymorphic_filter_value(value, association) if association
193
-
194
190
  inheritance = representation_class.inheritance_for_column(key)
195
191
  value = transform_sti_filter_value(value, inheritance) if inheritance
196
-
197
192
  column_type = target_klass.type_for_attribute(key).type
198
193
  return nil if column_type.nil?
199
194
 
@@ -264,7 +259,6 @@ module Apiwork
264
259
 
265
260
  nested_query = Filter.new(reflection.klass.all, association.representation_class)
266
261
  nested_conditions, nested_joins = nested_query.build_where_conditions(value, reflection.klass)
267
-
268
262
  [nested_conditions, { key => (nested_joins.any? ? nested_joins : {}) }]
269
263
  end
270
264
 
@@ -295,9 +289,7 @@ module Apiwork
295
289
 
296
290
  def build_string_where_clause(key, value, target_klass)
297
291
  column = target_klass.arel_table[key]
298
-
299
292
  normalizer = ->(value) { value.is_a?(String) || value.nil? ? { eq: value } : value }
300
-
301
293
  builder = Builder.new(column, key, allowed_types: [Hash])
302
294
 
303
295
  builder.build(
@@ -318,12 +310,10 @@ module Apiwork
318
310
 
319
311
  def build_date_where_clause(key, value, target_klass)
320
312
  column = target_klass.arel_table[key]
321
-
322
313
  return handle_nil_value(column) if value.nil?
323
314
  return column.eq(value) unless value.is_a?(Hash)
324
315
 
325
316
  normalizer = ->(value) { value }
326
-
327
317
  builder = Builder.new(column, key, allowed_types: [Hash])
328
318
 
329
319
  builder.build(value, normalizer:, valid_operators: Constants::NULLABLE_DATE_OPERATORS) do |operator, compare|
@@ -351,12 +341,10 @@ module Apiwork
351
341
 
352
342
  def build_time_where_clause(key, value, target_klass)
353
343
  column = target_klass.arel_table[key]
354
-
355
344
  return handle_nil_value(column) if value.nil?
356
345
  return column.eq(value) unless value.is_a?(Hash)
357
346
 
358
347
  normalizer = ->(value) { value }
359
-
360
348
  builder = Builder.new(column, key, allowed_types: [Hash])
361
349
 
362
350
  builder.build(value, normalizer:, valid_operators: Constants::NULLABLE_DATE_OPERATORS) do |operator, compare|
@@ -380,9 +368,7 @@ module Apiwork
380
368
 
381
369
  def build_numeric_where_clause(key, value, target_klass)
382
370
  column = target_klass.arel_table[key]
383
-
384
371
  normalizer = ->(value) { value.is_a?(Numeric) || value.nil? ? { eq: value } : value }
385
-
386
372
  builder = Builder.new(column, key, allowed_types: [Hash])
387
373
 
388
374
  builder.build(
@@ -412,9 +398,7 @@ module Apiwork
412
398
 
413
399
  def build_boolean_where_clause(key, value, target_klass)
414
400
  column = target_klass.arel_table[key]
415
-
416
401
  normalizer = ->(value) { [true, false, nil].include?(value) ? { eq: value } : value }
417
-
418
402
  builder = Builder.new(column, key, allowed_types: [Hash])
419
403
 
420
404
  builder.build(
@@ -8,8 +8,11 @@ module Apiwork
8
8
  capability_name :filtering
9
9
 
10
10
  request_transformer RequestTransformer
11
+
11
12
  api_builder APIBuilder
13
+
12
14
  contract_builder ContractBuilder
15
+
13
16
  operation Operation
14
17
  end
15
18
  end
@@ -9,7 +9,6 @@ module Apiwork
9
9
  def apply
10
10
  params = request.query.fetch(:include, {})
11
11
  includes = IncludesResolver.resolve(representation_class, params, include_always: true)
12
-
13
12
  result(includes:, serialize_options: { include: params })
14
13
  end
15
14
  end
@@ -8,6 +8,7 @@ module Apiwork
8
8
  capability_name :including
9
9
 
10
10
  contract_builder ContractBuilder
11
+
11
12
  operation Operation
12
13
  end
13
14
  end
@@ -25,7 +25,6 @@ module Apiwork
25
25
  records = fetch_records(size)
26
26
  has_more = records.length > size
27
27
  records = records.first(size)
28
-
29
28
  { data: records, metadata: build_metadata(records, has_more) }
30
29
  end
31
30
 
@@ -12,7 +12,9 @@ module Apiwork
12
12
  option :max_size, default: 100, type: :integer
13
13
 
14
14
  api_builder APIBuilder
15
+
15
16
  contract_builder ContractBuilder
17
+
16
18
  operation Operation
17
19
  end
18
20
  end
@@ -8,7 +8,9 @@ module Apiwork
8
8
  capability_name :sorting
9
9
 
10
10
  api_builder APIBuilder
11
+
11
12
  contract_builder ContractBuilder
13
+
12
14
  operation Operation
13
15
  end
14
16
  end
@@ -187,7 +187,6 @@ module Apiwork
187
187
 
188
188
  polymorphic_options = polymorphic_type_options(attribute)
189
189
  options.merge!(polymorphic_options) if polymorphic_options
190
-
191
190
  options
192
191
  end
193
192
 
@@ -196,7 +195,6 @@ module Apiwork
196
195
  return nil unless association
197
196
 
198
197
  allowed_values = association.polymorphic.map(&:polymorphic_name)
199
-
200
198
  { enum: allowed_values }
201
199
  end
202
200
 
@@ -208,7 +206,6 @@ module Apiwork
208
206
  deprecated: association.deprecated?,
209
207
  description: association.description,
210
208
  example: association.example,
211
- nullable: association.nullable?,
212
209
  optional: true,
213
210
  }
214
211
 
@@ -237,7 +234,6 @@ module Apiwork
237
234
 
238
235
  alias_name = representation_class.root_key.singular.to_sym
239
236
  import(association_contract, as: alias_name)
240
-
241
237
  [alias_name, 'nested_payload'].join('_').to_sym
242
238
  end
243
239
 
@@ -22,6 +22,7 @@ module Apiwork
22
22
  method(:translate),
23
23
  root_path: [representation_class.root_key.singular.to_sym],
24
24
  )
25
+
25
26
  raise DomainError, issues
26
27
  end
27
28
  end
@@ -8,7 +8,9 @@ module Apiwork
8
8
  capability_name :writing
9
9
 
10
10
  request_transformer RequestTransformer
11
+
11
12
  contract_builder ContractBuilder
13
+
12
14
  operation Operation
13
15
  end
14
16
  end
@@ -6,10 +6,13 @@ module Apiwork
6
6
  adapter_name :standard
7
7
 
8
8
  resource_serializer Serializer::Resource::Default
9
+
9
10
  error_serializer Serializer::Error::Default
10
11
 
11
12
  member_wrapper Wrapper::Member::Default
13
+
12
14
  collection_wrapper Wrapper::Collection::Default
15
+
13
16
  error_wrapper Wrapper::Error::Default
14
17
 
15
18
  capability Capability::Filtering
@@ -30,6 +30,7 @@ module Apiwork
30
30
  end
31
31
 
32
32
  object?(:meta)
33
+
33
34
  metadata_type_names.each { |type_name| merge(type_name) }
34
35
  end
35
36
 
@@ -22,7 +22,9 @@ module Apiwork
22
22
  class Default < Base
23
23
  shape do
24
24
  reference(root_key.singular.to_sym, to: data_type)
25
+
25
26
  object?(:meta)
27
+
26
28
  metadata_type_names.each { |type_name| merge(type_name) }
27
29
  end
28
30
 
@@ -333,9 +333,11 @@ module Apiwork
333
333
  return @locales if locale_keys.empty?
334
334
 
335
335
  locale_keys = locale_keys.flatten.uniq
336
+
336
337
  locale_keys.each do |locale_key|
337
338
  raise ConfigurationError, "locales must be symbols, got #{locale_key.class}: #{locale_key}" unless locale_key.is_a?(Symbol)
338
339
  end
340
+
339
341
  @locales = locale_keys
340
342
  end
341
343
 
@@ -356,6 +358,7 @@ module Apiwork
356
358
  return @raises if error_code_keys.empty?
357
359
 
358
360
  error_code_keys = error_code_keys.flatten.uniq
361
+
359
362
  error_code_keys.each do |error_code_key|
360
363
  unless error_code_key.is_a?(Symbol)
361
364
  hint = error_code_key.is_a?(Integer) ? " Use :#{ErrorCode.key_for_status(error_code_key)} instead." : ''
@@ -368,6 +371,7 @@ module Apiwork
368
371
  "Unknown error code :#{error_code_key}. Register it with: " \
369
372
  "Apiwork::ErrorCode.register :#{error_code_key}, status: <status>"
370
373
  end
374
+
371
375
  @raises = error_code_keys
372
376
  end
373
377
 
@@ -695,7 +699,6 @@ module Apiwork
695
699
  @path_format = :keep
696
700
  @introspect_cache = {}
697
701
  @introspect_contract_cache = {}
698
-
699
702
  Registry.register(self)
700
703
  end
701
704
 
@@ -724,7 +727,6 @@ module Apiwork
724
727
 
725
728
  def transform_key(key)
726
729
  key_string = key.to_s
727
-
728
730
  return key_string if key_string.match?(/\A[A-Z]+\z/)
729
731
 
730
732
  case key_format
@@ -738,7 +740,6 @@ module Apiwork
738
740
 
739
741
  def normalize_key(key)
740
742
  key_string = key.to_s
741
-
742
743
  return key_string if key_string.match?(/\A[A-Z]+\z/)
743
744
 
744
745
  key_string.underscore
@@ -815,15 +816,12 @@ module Apiwork
815
816
  return if @built_contracts.include?(contract_class)
816
817
 
817
818
  ensure_pre_pass_complete!
818
-
819
819
  representation_class = contract_class.representation_class
820
820
  return unless representation_class
821
821
 
822
822
  @built_contracts.add(contract_class)
823
-
824
823
  resource = @root_resource.find_resource { |resource| resource.resolve_contract_class == contract_class }
825
824
  resource_actions = resource ? resource.actions : {}
826
-
827
825
  adapter.register_contract(contract_class, representation_class, resource_actions:)
828
826
  end
829
827
 
@@ -877,6 +875,7 @@ module Apiwork
877
875
 
878
876
  def mark_nested_writable_representations!
879
877
  visited = Set.new
878
+
880
879
  @root_resource.each_resource do |resource|
881
880
  representation_class = resource.resolve_contract_class&.representation_class
882
881
  next unless representation_class
@@ -910,7 +909,6 @@ module Apiwork
910
909
  return unless contract_class.representation_class
911
910
 
912
911
  @built_contracts.add(contract_class)
913
-
914
912
  adapter.register_contract(contract_class, contract_class.representation_class, resource_actions: resource.actions)
915
913
  end
916
914
  end
@@ -127,9 +127,9 @@ module Apiwork
127
127
  value:,
128
128
  of: resolved_of,
129
129
  }.compact
130
+
130
131
  param_hash[:default] = default unless UNSET.equal?(default)
131
132
  param_hash[:shape] = resolved_shape if resolved_shape
132
-
133
133
  @params[name] = (@params[name] || {}).merge(param_hash)
134
134
  end
135
135
 
@@ -62,7 +62,6 @@ module Apiwork
62
62
  @param = param
63
63
  @path = path
64
64
  @singular = singular
65
-
66
65
  @crud_actions = name ? determine_crud_actions(singular, except:, only:) : []
67
66
  @custom_actions = []
68
67
  @resources = {}
@@ -119,6 +118,7 @@ module Apiwork
119
118
 
120
119
  def find_resource_for_path(resource_path)
121
120
  current = nil
121
+
122
122
  resource_path.split('/').each do |part|
123
123
  next if part.empty?
124
124
 
@@ -129,6 +129,7 @@ module Apiwork
129
129
 
130
130
  current = found
131
131
  end
132
+
132
133
  current
133
134
  end
134
135
 
@@ -213,11 +214,11 @@ module Apiwork
213
214
  param:,
214
215
  path:,
215
216
  }.compact
216
- build_resource(resource_name, options:, singular: false)
217
217
 
218
+ build_resource(resource_name, options:, singular: false)
218
219
  @resource_stack.push(resource_name)
219
-
220
220
  self.concerns(*concerns) if concerns
221
+
221
222
  if block
222
223
  block.arity.positive? ? yield(self) : instance_eval(&block)
223
224
  end
@@ -286,11 +287,11 @@ module Apiwork
286
287
  param:,
287
288
  path:,
288
289
  }.compact
289
- build_resource(resource_name, options:, singular: true)
290
290
 
291
+ build_resource(resource_name, options:, singular: true)
291
292
  @resource_stack.push(resource_name)
292
-
293
293
  self.concerns(*concerns) if concerns
294
+
294
295
  if block
295
296
  block.arity.positive? ? yield(self) : instance_eval(&block)
296
297
  end
@@ -321,9 +322,7 @@ module Apiwork
321
322
  def with_options(options = {}, &block)
322
323
  old_options = @current_options
323
324
  @current_options = merged_options(options)
324
-
325
325
  block.arity.positive? ? yield(self) : instance_eval(&block)
326
-
327
326
  @current_options = old_options
328
327
  end
329
328
 
@@ -489,6 +488,7 @@ module Apiwork
489
488
  resource.instance_exec(options, &block)
490
489
  end
491
490
  end
491
+
492
492
  @concerns[concern_name] = callable
493
493
  end
494
494
 
@@ -518,10 +518,12 @@ module Apiwork
518
518
 
519
519
  def collect_all_representation_classes
520
520
  representation_classes = []
521
+
521
522
  each_resource do |resource|
522
523
  representation_class = resource.representation_class
523
524
  representation_classes << representation_class if representation_class
524
525
  end
526
+
525
527
  representation_classes
526
528
  end
527
529
 
@@ -542,10 +544,8 @@ module Apiwork
542
544
 
543
545
  def build_resource(resource_name, options:, singular:)
544
546
  merged = merged_options(options)
545
-
546
547
  parent_name = @resource_stack.last
547
548
  parent_resource = parent_name ? find_resource(parent_name) : nil
548
-
549
549
  contract = merged.delete(:contract)
550
550
 
551
551
  resource = Resource.new(
@@ -608,6 +608,7 @@ module Apiwork
608
608
 
609
609
  def contract_path_to_class_name(contract_path)
610
610
  namespaces = @api_class.namespaces
611
+
611
612
  parts = if contract_path.start_with?('/')
612
613
  contract_path[1..].split('/')
613
614
  else
@@ -616,7 +617,6 @@ module Apiwork
616
617
 
617
618
  parts = parts.map { |part| part.to_s.camelize }
618
619
  parts[-1] = parts[-1].singularize
619
-
620
620
  "#{parts.join('::')}Contract"
621
621
  end
622
622
 
@@ -12,7 +12,6 @@ module Apiwork
12
12
  def draw
13
13
  api_classes = Registry.values
14
14
  router = self
15
-
16
15
  set = ActionDispatch::Routing::RouteSet.new
17
16
 
18
17
  set.draw do
@@ -87,6 +87,7 @@ module Apiwork
87
87
 
88
88
  def merge(key, block:, deprecated:, description:, example:)
89
89
  definition = @store[key]
90
+
90
91
  @store[key] = definition.merge(
91
92
  block:,
92
93
  deprecated:,
@@ -38,7 +38,6 @@ module Apiwork
38
38
  @default = default
39
39
  @enum = enum
40
40
  @children = children || {}
41
-
42
41
  return unless block && type == :hash
43
42
 
44
43
  block.arity.positive? ? yield(self) : instance_eval(&block)
@@ -13,6 +13,7 @@ module Apiwork
13
13
  when :integer then value.is_a?(Integer)
14
14
  when :hash then value.is_a?(Hash)
15
15
  end
16
+
16
17
  raise ConfigurationError, "#{name} must be #{type}, got #{value.class}" unless valid
17
18
  end
18
19