apiwork 0.7.0 → 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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -2
  3. data/app/controllers/apiwork/exports_controller.rb +0 -2
  4. data/lib/apiwork/adapter/base.rb +10 -2
  5. data/lib/apiwork/adapter/capability/base.rb +2 -0
  6. data/lib/apiwork/adapter/capability/contract/scope.rb +0 -1
  7. data/lib/apiwork/adapter/capability/operation/base.rb +1 -0
  8. data/lib/apiwork/adapter/capability/runner.rb +0 -1
  9. data/lib/apiwork/adapter/serializer/resource/base.rb +0 -1
  10. data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +1 -2
  11. data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +0 -3
  12. data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +0 -16
  13. data/lib/apiwork/adapter/standard/capability/filtering.rb +3 -0
  14. data/lib/apiwork/adapter/standard/capability/including/operation.rb +0 -1
  15. data/lib/apiwork/adapter/standard/capability/including.rb +1 -0
  16. data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +0 -1
  17. data/lib/apiwork/adapter/standard/capability/pagination.rb +2 -0
  18. data/lib/apiwork/adapter/standard/capability/sorting.rb +2 -0
  19. data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +0 -4
  20. data/lib/apiwork/adapter/standard/capability/writing/operation.rb +1 -0
  21. data/lib/apiwork/adapter/standard/capability/writing.rb +2 -0
  22. data/lib/apiwork/adapter/standard.rb +3 -0
  23. data/lib/apiwork/adapter/wrapper/collection/default.rb +1 -0
  24. data/lib/apiwork/adapter/wrapper/member/default.rb +2 -0
  25. data/lib/apiwork/api/base.rb +5 -7
  26. data/lib/apiwork/api/object.rb +8 -7
  27. data/lib/apiwork/api/resource.rb +10 -10
  28. data/lib/apiwork/api/router.rb +0 -1
  29. data/lib/apiwork/api/type_registry.rb +1 -0
  30. data/lib/apiwork/configuration/option.rb +0 -1
  31. data/lib/apiwork/configuration/validatable.rb +1 -0
  32. data/lib/apiwork/configuration.rb +1 -0
  33. data/lib/apiwork/contract/action/request.rb +4 -0
  34. data/lib/apiwork/contract/action/response.rb +1 -0
  35. data/lib/apiwork/contract/action.rb +2 -2
  36. data/lib/apiwork/contract/base.rb +3 -3
  37. data/lib/apiwork/contract/object/coercer.rb +0 -2
  38. data/lib/apiwork/contract/object/deserializer.rb +0 -1
  39. data/lib/apiwork/contract/object/transformer.rb +0 -1
  40. data/lib/apiwork/contract/object/validator.rb +13 -19
  41. data/lib/apiwork/contract/object.rb +14 -14
  42. data/lib/apiwork/contract/request_parser.rb +0 -2
  43. data/lib/apiwork/controller.rb +3 -6
  44. data/lib/apiwork/engine.rb +1 -0
  45. data/lib/apiwork/error_code/registry.rb +0 -1
  46. data/lib/apiwork/export/apiwork.rb +1 -0
  47. data/lib/apiwork/export/apiwork_mapper.rb +0 -1
  48. data/lib/apiwork/export/base.rb +2 -3
  49. data/lib/apiwork/export/open_api.rb +4 -11
  50. data/lib/apiwork/export/pipeline/writer.rb +1 -1
  51. data/lib/apiwork/export/pipeline.rb +0 -5
  52. data/lib/apiwork/export/sorbus.rb +2 -0
  53. data/lib/apiwork/export/sorbus_mapper.rb +1 -5
  54. data/lib/apiwork/export/surface_resolver.rb +6 -4
  55. data/lib/apiwork/export/type_analysis.rb +2 -1
  56. data/lib/apiwork/export/type_script.rb +2 -0
  57. data/lib/apiwork/export/type_script_mapper.rb +0 -8
  58. data/lib/apiwork/export/zod.rb +4 -2
  59. data/lib/apiwork/export/zod_mapper.rb +0 -8
  60. data/lib/apiwork/introspection/dump/action.rb +1 -1
  61. data/lib/apiwork/introspection/dump/api.rb +0 -4
  62. data/lib/apiwork/introspection/dump/contract.rb +0 -6
  63. data/lib/apiwork/introspection/dump/param.rb +6 -6
  64. data/lib/apiwork/introspection/dump/resource.rb +1 -0
  65. data/lib/apiwork/introspection/dump/type.rb +5 -5
  66. data/lib/apiwork/object.rb +12 -4
  67. data/lib/apiwork/reference_generator.rb +10 -10
  68. data/lib/apiwork/registry.rb +1 -0
  69. data/lib/apiwork/representation/association.rb +3 -3
  70. data/lib/apiwork/representation/attribute.rb +1 -5
  71. data/lib/apiwork/representation/base.rb +2 -5
  72. data/lib/apiwork/representation/deserializer.rb +0 -1
  73. data/lib/apiwork/representation/inheritance.rb +22 -10
  74. data/lib/apiwork/representation/model_detector.rb +1 -0
  75. data/lib/apiwork/representation/serializer.rb +3 -2
  76. data/lib/apiwork/version.rb +1 -1
  77. data/lib/apiwork.rb +9 -8
  78. metadata +4 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7614067b7732803415ef2038394b28590c02e63734cdf9b879aab126dcb1caee
4
- data.tar.gz: 2a7399c16a27c51c64e92811e7c020b863de65e4fdaaa7f4e400d7c8c308a94b
3
+ metadata.gz: ffc0d344ecd8ffd9db4568c2c57bff2d1c6770339045bbbc6b48ea3c14304688
4
+ data.tar.gz: ab453fab98baf8460e981af69fa1693f2538d85d9929a870f0427035e0a27ab5
5
5
  SHA512:
6
- metadata.gz: 58e21417d9e0fa2e6d4bd05106f4619282fc2925af365433902392f2d841eda8e4035ffb4800e0dbd96a09cf513a507237b6ec0bb31de2f648c48d8e6bd00b38
7
- data.tar.gz: de1ce6873f0c20373ce9bab1cd8e70b4b1787b6ae9adbf2f5fcb1c65720df33e45ad05aea524a8720837a777b7e50059c8a9d02240a1ddff57e9d69ad6422caf
6
+ metadata.gz: 3f61e2986a8605b629450668fac8050630e86de75ec858384a41c24a334717c85aa80ab139f393d16fb1e109f98a719b7749ef39ee593896a8863ca4b963935d
7
+ data.tar.gz: 3751ed380242dcb30a4fba2fa990a000b093071e8d393dd533551a3089d4cc915190d1f9f638c8d29062d6125e67f2a770dcbc0d5c00e6917415924d6aabb16e
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # Apiwork
2
2
 
3
- ![Apiwork](docs/public/logo-light.svg#gh-light-mode-only)
4
- ![Apiwork](docs/public/logo-dark.svg#gh-dark-mode-only)
3
+ ![Apiwork](docs/public/banner.svg)
4
+
5
+ ---
6
+
7
+ > 🚧 **Apiwork is pre-1.0 and working toward a stable 1.0.** Minor versions can still bring breaking changes, so follow the [changelog](./CHANGELOG.md).
8
+
9
+ ---
5
10
 
6
11
  [![Gem Version](https://img.shields.io/gem/v/apiwork)](https://rubygems.org/gems/apiwork)
7
12
  [![CI](https://github.com/skiftle/apiwork/actions/workflows/ci.yml/badge.svg)](https://github.com/skiftle/apiwork/actions/workflows/ci.yml)
@@ -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
@@ -37,7 +37,7 @@ module Apiwork
37
37
  # @param as [Symbol, nil] (nil)
38
38
  # The target attribute name.
39
39
  # @param default [Object] (UNSET)
40
- # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
40
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
41
41
  # @param deprecated [Boolean] (false)
42
42
  # Whether deprecated. Metadata included in exports.
43
43
  # @param description [String, nil] (nil)
@@ -61,7 +61,7 @@ module Apiwork
61
61
  # @param of [Symbol, Hash, nil] (nil)
62
62
  # The element or value type. Arrays and records only.
63
63
  # @param optional [Boolean] (false)
64
- # Whether the param is optional.
64
+ # Whether the param is optional. Always `true` for params with a `default`.
65
65
  # @param required [Boolean] (false)
66
66
  # Whether the param is required.
67
67
  # @param shape [API::Object, API::Union, nil] (nil)
@@ -103,6 +103,7 @@ module Apiwork
103
103
  value: nil,
104
104
  &block
105
105
  )
106
+ optional = normalize_optional(optional, default)
106
107
  resolved_of = resolve_of(of, type, &block)
107
108
  resolved_shape = [:array, :record].include?(type) ? nil : (shape || build_shape(type, discriminator, &block))
108
109
  discriminator = resolved_of&.discriminator if type == :array
@@ -126,9 +127,9 @@ module Apiwork
126
127
  value:,
127
128
  of: resolved_of,
128
129
  }.compact
130
+
129
131
  param_hash[:default] = default unless UNSET.equal?(default)
130
132
  param_hash[:shape] = resolved_shape if resolved_shape
131
-
132
133
  @params[name] = (@params[name] || {}).merge(param_hash)
133
134
  end
134
135
 
@@ -140,7 +141,7 @@ module Apiwork
140
141
  # @param as [Symbol, nil] (nil)
141
142
  # The target attribute name.
142
143
  # @param default [Object] (UNSET)
143
- # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
144
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
144
145
  # @param deprecated [Boolean] (false)
145
146
  # Whether deprecated. Metadata included in exports.
146
147
  # @param description [String, nil] (nil)
@@ -148,7 +149,7 @@ module Apiwork
148
149
  # @param nullable [Boolean] (false)
149
150
  # Whether the value can be `null`.
150
151
  # @param optional [Boolean] (false)
151
- # Whether the param is optional.
152
+ # Whether the param is optional. Always `true` for params with a `default`.
152
153
  # @param required [Boolean] (false)
153
154
  # Whether the param is required.
154
155
  # @yield block for defining element type
@@ -203,7 +204,7 @@ module Apiwork
203
204
  # @param as [Symbol, nil] (nil)
204
205
  # The target attribute name.
205
206
  # @param default [Object] (UNSET)
206
- # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
207
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default. A param with a default is always optional.
207
208
  # @param deprecated [Boolean] (false)
208
209
  # Whether deprecated. Metadata included in exports.
209
210
  # @param description [String, nil] (nil)
@@ -211,7 +212,7 @@ module Apiwork
211
212
  # @param nullable [Boolean] (false)
212
213
  # Whether the value can be `null`.
213
214
  # @param optional [Boolean] (false)
214
- # Whether the param is optional.
215
+ # Whether the param is optional. Always `true` for params with a `default`.
215
216
  # @param required [Boolean] (false)
216
217
  # Whether the param is required.
217
218
  # @yield block for defining value type