spree_api 6.0.5 → 6.0.6

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v3/error_handler.rb +4 -0
  3. data/app/controllers/spree/api/v3/admin/gift_cards_controller.rb +6 -0
  4. data/app/controllers/spree/api/v3/admin/order_groups_controller.rb +1 -1
  5. data/app/controllers/spree/api/v3/admin/orders/payments_controller.rb +10 -6
  6. data/app/controllers/spree/api/v3/store/products/filters_controller.rb +1 -0
  7. data/app/controllers/spree/api/v3/webhooks/payments_controller.rb +36 -6
  8. data/app/serializers/spree/api/v3/admin/admin_user_serializer.rb +4 -2
  9. data/app/serializers/spree/api/v3/admin/commission_rule_serializer.rb +3 -3
  10. data/app/serializers/spree/api/v3/admin/consent_record_serializer.rb +1 -1
  11. data/app/serializers/spree/api/v3/admin/import_serializer.rb +4 -1
  12. data/app/serializers/spree/api/v3/admin/order_serializer.rb +11 -0
  13. data/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb +5 -1
  14. data/app/serializers/spree/api/v3/admin/payment_serializer.rb +5 -2
  15. data/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb +3 -1
  16. data/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb +4 -4
  17. data/app/serializers/spree/api/v3/admin/refund_serializer.rb +5 -2
  18. data/app/serializers/spree/api/v3/cart_serializer.rb +16 -3
  19. data/app/serializers/spree/api/v3/company_serializer.rb +2 -2
  20. data/app/serializers/spree/api/v3/credit_card_serializer.rb +5 -1
  21. data/app/serializers/spree/api/v3/fulfillment_serializer.rb +4 -1
  22. data/app/serializers/spree/api/v3/payment_serializer.rb +3 -1
  23. data/app/serializers/spree/api/v3/product_filters_serializer.rb +1 -1
  24. data/app/serializers/spree/api/v3/product_serializer.rb +9 -1
  25. data/app/serializers/spree/api/v3/seller/import_serializer.rb +4 -1
  26. data/app/serializers/spree/api/v3/variant_serializer.rb +3 -1
  27. data/app/services/spree/api/v3/filter_table.rb +11 -26
  28. data/app/services/spree/api/v3/filters_aggregator.rb +13 -18
  29. data/config/locales/en.yml +1 -0
  30. data/lib/spree/api/enum_types.rb +7 -4
  31. data/lib/spree/api/openapi/schema_helper.rb +15 -234
  32. data/lib/spree/api/sdk_types.rb +5 -5
  33. data/openapi/admin.yaml +149 -151
  34. data/openapi/store.yaml +84 -144
  35. metadata +8 -9
  36. data/lib/spree/api/testing_support/always_register_type_hints.rb +0 -28
@@ -122,71 +122,6 @@ module Spree
122
122
  },
123
123
  required: %w[allow actions subjects has_conditions]
124
124
  },
125
- ImportSchemaField: {
126
- type: :object,
127
- description: 'A canonical column of an import type, including per-store custom field columns',
128
- properties: {
129
- name: { type: :string, description: 'Canonical field name used in mappings', example: 'slug' },
130
- label: { type: :string, description: 'Human-readable label', example: 'Slug' },
131
- required: { type: :boolean, description: 'Whether the field must be mapped before processing' }
132
- },
133
- required: %w[name label required]
134
- },
135
- CheckoutRequirement: {
136
- type: :object,
137
- properties: {
138
- step: { type: :string, description: 'Checkout step this requirement belongs to', example: 'payment' },
139
- field: { type: :string, description: 'Field that needs to be satisfied', example: 'payment' },
140
- message: { type: :string, description: 'Human-readable requirement message', example: 'Add a payment method' }
141
- },
142
- required: %w[step field message]
143
- },
144
- CartWarning: {
145
- type: :object,
146
- description: 'A warning about a cart issue (e.g., item removed due to stock change)',
147
- properties: {
148
- code: { type: :string, description: 'Machine-readable warning code', example: 'line_item_removed' },
149
- message: { type: :string, description: 'Human-readable warning message', example: 'Blue T-Shirt was removed because it was sold out' },
150
- line_item_id: { type: :string, nullable: true, description: 'Prefixed line item ID (when applicable)', example: 'li_abc123' },
151
- variant_id: { type: :string, nullable: true, description: 'Prefixed variant ID (when applicable)', example: 'variant_abc123' },
152
- item_index: {
153
- type: :integer,
154
- nullable: true,
155
- description: 'Position in the submitted items array, for warnings raised while applying a batch of item changes',
156
- example: 1
157
- }
158
- },
159
- required: %w[code message]
160
- },
161
- FulfillmentManifestItem: {
162
- type: :object,
163
- description: 'An item within a fulfillment — which line item and how many units are in this fulfillment',
164
- properties: {
165
- item_id: { type: :string, description: 'Line item ID', example: 'li_abc123' },
166
- variant_id: { type: :string, description: 'Variant ID', example: 'variant_abc123' },
167
- quantity: { type: :integer, description: 'Quantity in this fulfillment', example: 2 }
168
- },
169
- required: %w[item_id variant_id quantity]
170
- },
171
- AdminUserRoleAssignment: {
172
- type: :object,
173
- description: 'A role assignment for the current store on a staff member',
174
- properties: {
175
- id: { type: :string, description: 'Prefixed role ID', example: 'role_abc123' },
176
- name: { type: :string, description: 'Role name', example: 'admin' }
177
- },
178
- required: %w[id name]
179
- },
180
- AdminUserStore: {
181
- type: :object,
182
- description: 'A store the staff member can access through a role assignment',
183
- properties: {
184
- id: { type: :string, description: 'Prefixed store ID', example: 'store_abc123' },
185
- name: { type: :string, description: 'Store name', example: 'My Store' },
186
- code: { type: :string, description: 'Store code', example: 'my-store' }
187
- },
188
- required: %w[id name code]
189
- },
190
125
  PreferenceSchema: {
191
126
  type: :object,
192
127
  description: 'The JSON Schema (draft 2020-12) of a type\'s `preferences`: one property per setting, ' \
@@ -194,15 +129,6 @@ module Spree
194
129
  '`x-spree-secret` for a secret and `x-spree-prefix` for an id list. Unknown keys are refused.',
195
130
  additionalProperties: true,
196
131
  example: { type: 'object', properties: { amount: { type: 'string', format: 'money', default: '0.0' } }, additionalProperties: false }
197
- },
198
- PromotionActionLineItem: {
199
- type: :object,
200
- description: 'One row in a `create_line_items` action — the variant added to the order and how many',
201
- properties: {
202
- variant_id: { type: :string, example: 'variant_abc123' },
203
- quantity: { type: :integer, example: 1 }
204
- },
205
- required: %w[variant_id quantity]
206
132
  }
207
133
  }
208
134
  end
@@ -383,27 +309,21 @@ module Spree
383
309
  private
384
310
 
385
311
  def typelizer_schemas(writer_name)
386
- with_typelizer_enabled do
387
- schemas = Typelizer.openapi_schemas(writer_name: writer_name)
388
- schemas.each_value do |s|
389
- s[:'x-typelizer'] = true
390
- strip_null_from_enums(s)
391
- end
392
- patch_typescript_only_types(schemas, writer_name)
393
- patch_cart_schema(schemas)
394
- patch_fulfillment_schema(schemas)
395
- patch_admin_user_schema(schemas)
396
- patch_promotion_rule_schema(schemas)
397
- patch_promotion_action_schema(schemas)
398
- patch_import_schema(schemas)
399
- schemas
312
+ schemas = Typelizer.openapi_schemas(writer_name: writer_name)
313
+ schemas.each_value do |s|
314
+ s[:'x-typelizer'] = true
315
+ strip_null_from_enums(s)
400
316
  end
317
+ patch_typescript_only_types(schemas, writer_name)
318
+ patch_promotion_action_calculator(schemas)
319
+ schemas
401
320
  end
402
321
 
403
322
  # Typelizer publishes a type only TypeScript can express (`Array<{ … }>`,
404
323
  # `any`) as a plain object. Give each such property the shape the API
405
- # sends — an array, or any value — so responses validate against it;
406
- # the patches below then point some arrays at a named item component.
324
+ # sends — an array, or any value — so responses validate against it.
325
+ # A list of objects is better declared as an inline shape
326
+ # (`typelize({ id: :string }, multi: true)`), which documents its fields.
407
327
  def patch_typescript_only_types(schemas, writer_name)
408
328
  Typelizer.interfaces(writer_name: writer_name).each do |interface|
409
329
  properties = (schemas[interface.name] || schemas[interface.name.to_sym])&.dig(:properties)
@@ -428,125 +348,14 @@ module Spree
428
348
  end
429
349
  end
430
350
 
431
- # Same Array<{...}> issue as cart/fulfillment — patch Import#schema_fields
432
- # to reference the ImportSchemaField component schema.
433
- def patch_import_schema(schemas)
434
- import = schemas['Import'] || schemas[:Import]
435
- return unless import
436
-
437
- props = import[:properties]
438
- return unless props
439
-
440
- fields_key = props.key?('schema_fields') ? 'schema_fields' : :schema_fields
441
- if props[fields_key]
442
- props[fields_key] = {
443
- type: :array,
444
- items: { '$ref' => '#/components/schemas/ImportSchemaField' }
445
- }
446
- end
447
- end
448
-
449
- # Typelizer cannot represent Array<{...}> inline object types in OpenAPI,
450
- # so we patch them to reference manually-defined component schemas.
451
- def patch_cart_schema(schemas)
452
- cart = schemas['Cart'] || schemas[:Cart]
453
- return unless cart
454
-
455
- props = cart[:properties]
456
- return unless props
457
-
458
- req_key = props.key?('requirements') ? 'requirements' : :requirements
459
- if props[req_key]
460
- props[req_key] = {
461
- type: :array,
462
- items: { '$ref' => '#/components/schemas/CheckoutRequirement' }
463
- }
464
- end
465
-
466
- warn_key = props.key?('warnings') ? 'warnings' : :warnings
467
- if props[warn_key]
468
- props[warn_key] = {
469
- type: :array,
470
- items: { '$ref' => '#/components/schemas/CartWarning' }
471
- }
472
- end
473
- end
474
-
475
- # Same Array<{...}> issue as cart/fulfillment — patch AdminUser#roles
476
- # to reference the AdminUserRoleAssignment component schema.
477
- def patch_admin_user_schema(schemas)
478
- admin_user = schemas['AdminUser'] || schemas[:AdminUser]
479
- return unless admin_user
480
-
481
- props = admin_user[:properties]
482
- return unless props
483
-
484
- roles_key = props.key?('roles') ? 'roles' : :roles
485
- if props[roles_key]
486
- props[roles_key] = {
487
- type: :array,
488
- items: { '$ref' => '#/components/schemas/AdminUserRoleAssignment' }
489
- }
490
- end
491
-
492
- stores_key = props.key?('stores') ? 'stores' : :stores
493
- if props[stores_key]
494
- props[stores_key] = {
495
- type: :array,
496
- items: { '$ref' => '#/components/schemas/AdminUserStore' }
497
- }
498
- end
499
- end
500
-
501
- # Same Array<{...}> + Array<string> typelize hints that Typelizer
502
- # collapses to `object` in OpenAPI. Patch the affected properties to
503
- # their correct array shapes.
504
- def patch_promotion_rule_schema(schemas)
505
- rule = schemas['PromotionRule'] || schemas[:PromotionRule]
506
- return unless rule
507
-
508
- patch_id_arrays(rule, %w[product_ids category_ids customer_ids option_value_ids])
509
- end
510
-
511
- def patch_promotion_action_schema(schemas)
351
+ # The calculator's TypeScript type has another name than its component.
352
+ def patch_promotion_action_calculator(schemas)
512
353
  action = schemas['PromotionAction'] || schemas[:PromotionAction]
513
- return unless action
514
-
515
- props = action[:properties]
516
- return unless props
517
-
518
- calc_key = props.key?('calculator') ? 'calculator' : :calculator
519
- if props[calc_key]
520
- props[calc_key] = {
521
- allOf: [{ '$ref' => '#/components/schemas/PromotionActionCalculator' }],
522
- nullable: true
523
- }
524
- end
525
-
526
- items_key = props.key?('line_items') ? 'line_items' : :line_items
527
- if props[items_key]
528
- props[items_key] = {
529
- type: :array,
530
- items: { '$ref' => '#/components/schemas/PromotionActionLineItem' },
531
- nullable: true
532
- }
533
- end
534
- end
535
-
536
- def patch_id_arrays(schema, keys)
537
- props = schema[:properties]
354
+ props = action&.dig(:properties)
538
355
  return unless props
539
356
 
540
- keys.each do |key|
541
- actual = props.key?(key) ? key : key.to_sym
542
- next unless props[actual]
543
-
544
- props[actual] = {
545
- type: :array,
546
- items: { type: :string },
547
- nullable: true
548
- }
549
- end
357
+ key = props.key?('calculator') ? 'calculator' : :calculator
358
+ props[key] = { allOf: [{ '$ref' => '#/components/schemas/PromotionActionCalculator' }], nullable: true } if props[key]
550
359
  end
551
360
 
552
361
  # One component per subtype Spree ships (`PromotionRuleItemTotalPreferences`)
@@ -617,24 +426,6 @@ module Spree
617
426
  props[key] = { allOf: [{ '$ref' => '#/components/schemas/DeliveryMethodCalculator' }], nullable: true } if props[key]
618
427
  end
619
428
 
620
- # Typelizer cannot represent Array<{...}> inline object types in OpenAPI,
621
- # so we patch Fulfillment#items to reference the FulfillmentManifestItem component schema.
622
- def patch_fulfillment_schema(schemas)
623
- fulfillment = schemas['Fulfillment'] || schemas[:Fulfillment]
624
- return unless fulfillment
625
-
626
- props = fulfillment[:properties]
627
- return unless props
628
-
629
- items_key = props.key?('items') ? 'items' : :items
630
- if props[items_key]
631
- props[items_key] = {
632
- type: :array,
633
- items: { '$ref' => '#/components/schemas/FulfillmentManifestItem' }
634
- }
635
- end
636
- end
637
-
638
429
  # Typelizer adds nil to enum arrays for nullable fields.
639
430
  # OpenAPI 3.0 handles nullability via `nullable: true`, so the nil entry is redundant
640
431
  # and causes issues with code generators. The array is often a model's
@@ -647,16 +438,6 @@ module Spree
647
438
  prop[:enum] = prop[:enum].compact
648
439
  end
649
440
  end
650
-
651
- # Typelizer is normally disabled in test/production, but we need it
652
- # enabled to generate OpenAPI schemas from serializer type hints
653
- def with_typelizer_enabled
654
- original = ENV['TYPELIZER']
655
- ENV['TYPELIZER'] = 'true'
656
- yield
657
- ensure
658
- ENV['TYPELIZER'] = original
659
- end
660
441
  end
661
442
  end
662
443
  end
@@ -137,7 +137,10 @@ module Spree
137
137
  # Replaces the writers Spree configured for its own SDKs: run in an
138
138
  # extension's app, they would write core's types into the installed gem.
139
139
  def configure(serializers, out)
140
- ours = ->(serializer) { Object.const_source_location(serializer.name)&.first.to_s.start_with?("#{serializers}/") }
140
+ # An unnamed class has no source file to place it in the extension.
141
+ ours = lambda do |serializer|
142
+ serializer.name && Object.const_source_location(serializer.name)&.first.to_s.start_with?("#{serializers}/")
143
+ end
141
144
 
142
145
  Typelizer.configure do |config|
143
146
  config.reset_writers!
@@ -163,15 +166,12 @@ module Spree
163
166
  end
164
167
 
165
168
  def run_typelizer
166
- enabled = ENV['TYPELIZER']
167
169
  source = Typelizer::OpenEnums.source
168
- ENV['TYPELIZER'] = 'true'
169
170
  Typelizer::OpenEnums.source = nil
170
171
 
171
172
  require 'typelizer/generator'
172
- Typelizer::Generator.call(force: true)
173
+ Typelizer::Generator.call(force: true, skip_check: true)
173
174
  ensure
174
- ENV['TYPELIZER'] = enabled
175
175
  Typelizer::OpenEnums.source = source
176
176
  end
177
177