spree_api 6.0.6 → 6.0.7
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/Rakefile +3 -0
- data/app/controllers/concerns/spree/api/v3/admin/product_membership.rb +2 -2
- data/app/controllers/concerns/spree/api/v3/admin/validation_details.rb +34 -13
- data/app/controllers/concerns/spree/api/v3/authentication_strategies.rb +14 -8
- data/app/controllers/concerns/spree/api/v3/error_handler.rb +31 -4
- data/app/controllers/concerns/spree/api/v3/invitation_resend.rb +28 -0
- data/app/controllers/concerns/spree/api/v3/locale_and_currency.rb +1 -1
- data/app/controllers/concerns/spree/api/v3/resource_serializer.rb +5 -0
- data/app/controllers/concerns/spree/api/v3/scoped_authorization.rb +20 -3
- data/app/controllers/spree/api/v3/admin/admin_users_controller.rb +8 -3
- data/app/controllers/spree/api/v3/admin/api_keys_controller.rb +6 -1
- data/app/controllers/spree/api/v3/admin/auth_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/catalogs_controller.rb +2 -1
- data/app/controllers/spree/api/v3/admin/channels_controller.rb +2 -2
- data/app/controllers/spree/api/v3/admin/collection_rules_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/delivery_methods_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/email_templates_controller.rb +2 -2
- data/app/controllers/spree/api/v3/admin/exports_controller.rb +49 -0
- data/app/controllers/spree/api/v3/admin/gift_cards_controller.rb +9 -0
- data/app/controllers/spree/api/v3/admin/integrations_controller.rb +4 -2
- data/app/controllers/spree/api/v3/admin/invitation_acceptances_controller.rb +10 -3
- data/app/controllers/spree/api/v3/admin/invitations_controller.rb +4 -5
- data/app/controllers/spree/api/v3/admin/order_routing_rules_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/orders/payments_controller.rb +11 -3
- data/app/controllers/spree/api/v3/admin/password_resets_controller.rb +14 -2
- data/app/controllers/spree/api/v3/admin/payment_methods_controller.rb +23 -2
- data/app/controllers/spree/api/v3/admin/permissions_controller.rb +9 -3
- data/app/controllers/spree/api/v3/admin/products_controller.rb +18 -6
- data/app/controllers/spree/api/v3/admin/promotion_actions_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/promotion_rules_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/reporting_controller.rb +1 -5
- data/app/controllers/spree/api/v3/admin/sellers/invitations_controller.rb +12 -12
- data/app/controllers/spree/api/v3/admin/setup_controller.rb +2 -18
- data/app/controllers/spree/api/v3/admin/stock_levels_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/tags_controller.rb +1 -1
- data/app/controllers/spree/api/v3/admin/tax_providers_controller.rb +20 -0
- data/app/controllers/spree/api/v3/admin/translatable_resources_controller.rb +3 -1
- data/app/controllers/spree/api/v3/admin/translations_coverage_controller.rb +11 -9
- data/app/controllers/spree/api/v3/admin/webhook_events_controller.rb +9 -3
- data/app/controllers/spree/api/v3/base_controller.rb +39 -0
- data/app/controllers/spree/api/v3/resource_controller.rb +0 -18
- data/app/controllers/spree/api/v3/seller/invitation_acceptances_controller.rb +2 -2
- data/app/controllers/spree/api/v3/seller/invitations_controller.rb +11 -11
- data/app/controllers/spree/api/v3/seller/onboarding_controller.rb +1 -1
- data/app/controllers/spree/api/v3/seller/password_resets_controller.rb +12 -2
- data/app/controllers/spree/api/v3/seller/products_controller.rb +1 -1
- data/app/controllers/spree/api/v3/store/account/companies_controller.rb +7 -7
- data/app/controllers/spree/api/v3/store/auth_controller.rb +2 -2
- data/app/controllers/spree/api/v3/store/company_invitations_controller.rb +7 -4
- data/app/controllers/spree/api/v3/store/customer/password_resets_controller.rb +11 -1
- data/app/controllers/spree/api/v3/store/newsletter_subscribers_controller.rb +4 -3
- data/app/serializers/spree/api/v3/admin/api_key_serializer.rb +2 -1
- data/app/serializers/spree/api/v3/admin/bulk_product_result_serializer.rb +33 -0
- data/app/serializers/spree/api/v3/admin/bulk_stock_level_result_serializer.rb +17 -0
- data/app/serializers/spree/api/v3/admin/calculator_type_serializer.rb +19 -0
- data/app/serializers/spree/api/v3/admin/company_invitation_serializer.rb +5 -0
- data/app/serializers/spree/api/v3/admin/company_membership_serializer.rb +1 -0
- data/app/serializers/spree/api/v3/admin/country_serializer.rb +8 -0
- data/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb +2 -1
- data/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb +3 -0
- data/app/serializers/spree/api/v3/admin/integration_connection_result_serializer.rb +18 -0
- data/app/serializers/spree/api/v3/admin/integration_type_definition_serializer.rb +25 -0
- data/app/serializers/spree/api/v3/admin/password_reset_acknowledgement_serializer.rb +18 -0
- data/app/serializers/spree/api/v3/admin/payment_method_type_serializer.rb +17 -0
- data/app/serializers/spree/api/v3/admin/product_membership_result_serializer.rb +19 -0
- data/app/serializers/spree/api/v3/admin/reporting_dimension_value_serializer.rb +22 -0
- data/app/serializers/spree/api/v3/admin/reporting_metric_value_serializer.rb +49 -0
- data/app/serializers/spree/api/v3/admin/reporting_result_meta_serializer.rb +44 -0
- data/app/serializers/spree/api/v3/admin/reporting_result_serializer.rb +18 -55
- data/app/serializers/spree/api/v3/admin/reporting_row_serializer.rb +35 -0
- data/app/serializers/spree/api/v3/admin/resource_type_definition_serializer.rb +29 -0
- data/app/serializers/spree/api/v3/admin/setup_status_serializer.rb +17 -0
- data/app/serializers/spree/api/v3/admin/tag_serializer.rb +17 -0
- data/app/serializers/spree/api/v3/admin/translatable_resource_serializer.rb +28 -0
- data/app/serializers/spree/api/v3/admin/translation_coverage_serializer.rb +37 -0
- data/app/serializers/spree/api/v3/company_invitation_serializer.rb +10 -1
- data/app/serializers/spree/api/v3/company_membership_serializer.rb +2 -0
- data/app/serializers/spree/api/v3/fulfillment_serializer.rb +7 -6
- data/app/serializers/spree/api/v3/product_category_serializer.rb +2 -10
- data/app/serializers/spree/api/v3/product_collection_serializer.rb +2 -10
- data/app/serializers/spree/api/v3/seller/bulk_product_result_serializer.rb +22 -0
- data/app/serializers/spree/api/v3/seller/fulfillment_serializer.rb +1 -3
- data/app/serializers/spree/api/v3/seller/password_reset_acknowledgement_serializer.rb +18 -0
- data/app/serializers/spree/api/v3/seller/payout_account_link_serializer.rb +18 -0
- data/app/serializers/spree/api/v3/seller/stock_location_serializer.rb +8 -3
- data/app/services/spree/api/v3/filters_aggregator.rb +1 -5
- data/config/routes.rb +3 -1
- data/lib/spree/api/dependencies.rb +7 -2
- data/lib/spree/api/openapi/schema_helper.rb +86 -2
- data/lib/spree/api/preference_types.rb +8 -0
- data/lib/spree/api/testing_support/deterministic_openapi.rb +87 -0
- data/lib/spree/api/testing_support/openapi.rb +2 -1
- data/lib/spree/api/testing_support/openapi_tasks.rb +3 -0
- data/lib/spree/api/testing_support/response_schema.rb +64 -0
- data/lib/spree/api.rb +1 -0
- data/lib/typelizer/nullable_references.rb +31 -0
- data/openapi/admin.yaml +3571 -524
- data/openapi/store.yaml +353 -153
- metadata +29 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V3
|
|
4
|
+
module Admin
|
|
5
|
+
# A translatable resource type as the registry lists it: a plain hash
|
|
6
|
+
# from {Spree::Translations.registry}, so no id.
|
|
7
|
+
class TranslatableResourceSerializer
|
|
8
|
+
include Alba::Resource
|
|
9
|
+
include Typelizer::DSL
|
|
10
|
+
|
|
11
|
+
typelize resource_type: [:string, comment: 'The resource type as translation requests name it, e.g. product'],
|
|
12
|
+
readable: [:boolean, comment: "Whether one record's translations can be read on their own. " \
|
|
13
|
+
'A type that cannot is read as children of its parent, such as ' \
|
|
14
|
+
'option values under an option type, and written through the batch endpoint.']
|
|
15
|
+
|
|
16
|
+
attributes :resource_type
|
|
17
|
+
|
|
18
|
+
typelize({ key: [:string, comment: 'Field name, e.g. name'],
|
|
19
|
+
type: [:string, comment: 'How the field is edited: string or html'] },
|
|
20
|
+
multi: true, comment: 'The fields of a record that can be translated')
|
|
21
|
+
attribute(:fields) { |entry| entry[:fields] }
|
|
22
|
+
|
|
23
|
+
attributes :readable
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V3
|
|
4
|
+
module Admin
|
|
5
|
+
# How much of one resource type is translated: store-wide totals per
|
|
6
|
+
# locale and a page of its records. Built per request, so no id.
|
|
7
|
+
class TranslationCoverageSerializer
|
|
8
|
+
include Alba::Resource
|
|
9
|
+
include Typelizer::DSL
|
|
10
|
+
|
|
11
|
+
typelize resource_type: [:string, comment: 'The resource type the figures are for, e.g. product'],
|
|
12
|
+
default_locale: :string,
|
|
13
|
+
locales: [:string, multi: true, comment: 'The locales translated into: every supported locale but the default'],
|
|
14
|
+
field_count: [:number, comment: 'How many fields of a record can be translated'],
|
|
15
|
+
search_field: [:string, {
|
|
16
|
+
nullable: true, comment: 'The predicate `search` filters by, e.g. name_cont; null when the type has nothing searchable'
|
|
17
|
+
}]
|
|
18
|
+
|
|
19
|
+
attributes :resource_type, :default_locale, :locales, :field_count, :search_field
|
|
20
|
+
|
|
21
|
+
typelize({ locale: :string,
|
|
22
|
+
translated: [:number, comment: 'Records with every field translated'],
|
|
23
|
+
total: [:number, comment: 'Records of this type in the store'],
|
|
24
|
+
coverage: [:number, comment: 'The share translated, from 0 to 1'] },
|
|
25
|
+
multi: true, comment: 'Store-wide totals, one entry per locale')
|
|
26
|
+
attribute(:coverage) { |coverage| coverage[:coverage] }
|
|
27
|
+
|
|
28
|
+
typelize({ id: :string,
|
|
29
|
+
label: [:string, { nullable: true }],
|
|
30
|
+
locales: [:'Record<string, number>', comment: 'How many fields are translated, keyed by locale. Compare with field_count.'] },
|
|
31
|
+
multi: true, comment: 'This page of records')
|
|
32
|
+
attribute(:records) { |coverage| coverage[:records] }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -5,7 +5,9 @@ module Spree
|
|
|
5
5
|
# deliberately absent — it travels only in the invite email.
|
|
6
6
|
class CompanyInvitationSerializer < BaseSerializer
|
|
7
7
|
typelize email: :string, company_id: :string, status: [:string, enum: %w[pending accepted revoked expired], enum_type_name: 'CompanyInvitationStatus'],
|
|
8
|
-
expires_at: [:string, nullable: true]
|
|
8
|
+
expires_at: [:string, nullable: true],
|
|
9
|
+
company_name: [:string, optional: true, deprecated: 'Expand `company` and read its `name`. Removed in 6.5.'],
|
|
10
|
+
store_name: [:string, optional: true, deprecated: "Read the store's `name` from `GET /api/v3/store/store`. Removed in 6.5."]
|
|
9
11
|
|
|
10
12
|
attributes :email, expires_at: :iso8601
|
|
11
13
|
|
|
@@ -22,6 +24,13 @@ module Spree
|
|
|
22
24
|
else 'pending'
|
|
23
25
|
end
|
|
24
26
|
end
|
|
27
|
+
|
|
28
|
+
one :company, resource: proc { Spree.api.company_serializer }, if: proc { expand?('company') }
|
|
29
|
+
|
|
30
|
+
# Sent only by the token lookup, which named the company and the store
|
|
31
|
+
# before `company` could be expanded.
|
|
32
|
+
attribute(:company_name, if: proc { params[:invitee] }) { |invitation| invitation.company.name }
|
|
33
|
+
attribute(:store_name, if: proc { params[:invitee] }) { current_store.name }
|
|
25
34
|
end
|
|
26
35
|
end
|
|
27
36
|
end
|
|
@@ -8,7 +8,11 @@ module Spree
|
|
|
8
8
|
tracking: [:string, nullable: true], tracking_url: [:string, nullable: true],
|
|
9
9
|
fulfilled_at: [:string, nullable: true], delivered_at: [:string, nullable: true], unpriced: :boolean,
|
|
10
10
|
pickup_point_data: ['Record<string, unknown>', nullable: true],
|
|
11
|
-
selected_delivery_rate_id: [:string, nullable: true]
|
|
11
|
+
selected_delivery_rate_id: [:string, nullable: true],
|
|
12
|
+
pickup_location: { nullable: true,
|
|
13
|
+
comment: 'Where the customer collects a pickup — the counter chosen at checkout, ' \
|
|
14
|
+
'which can differ from the stock location it ships from. ' \
|
|
15
|
+
'Null unless the delivery is a pickup.' }
|
|
12
16
|
|
|
13
17
|
# +tracking+ and +tracking_url+ summarize the primary delivery; every
|
|
14
18
|
# consignment is listed under +deliveries+.
|
|
@@ -29,11 +33,7 @@ module Spree
|
|
|
29
33
|
|
|
30
34
|
attributes :status
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
# fulfillment_type backfill ran.
|
|
34
|
-
attribute :fulfillment_type do |fulfillment|
|
|
35
|
-
fulfillment.fulfillment_type.presence || (fulfillment.digital? ? 'digital' : 'shipping')
|
|
36
|
-
end
|
|
36
|
+
attributes :fulfillment_type
|
|
37
37
|
|
|
38
38
|
attributes fulfilled_at: :iso8601, delivered_at: :iso8601
|
|
39
39
|
|
|
@@ -60,6 +60,7 @@ module Spree
|
|
|
60
60
|
many :deliveries, resource: proc { Spree.api.delivery_serializer }
|
|
61
61
|
one :delivery_method, resource: proc { Spree.api.delivery_method_serializer }
|
|
62
62
|
one :stock_location, resource: proc { Spree.api.stock_location_serializer }
|
|
63
|
+
one :pickup_location, resource: proc { Spree.api.stock_location_serializer }
|
|
63
64
|
many :delivery_rates, resource: proc { Spree.api.delivery_rate_serializer }
|
|
64
65
|
many :tax_lines, resource: proc { Spree.api.tax_line_serializer }, if: proc { expand?('tax_lines') }
|
|
65
66
|
|
|
@@ -6,19 +6,11 @@ module Spree
|
|
|
6
6
|
category_id: [:string, nullable: true]
|
|
7
7
|
|
|
8
8
|
attribute :product_id do |product_category|
|
|
9
|
-
|
|
9
|
+
Spree::Product.prefixed_id_for(product_category.product_id)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
attribute :category_id do |product_category|
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def prefixed_id_for(klass, id)
|
|
19
|
-
return nil if id.nil?
|
|
20
|
-
|
|
21
|
-
"#{klass._prefix_id_prefix}_#{Spree::PrefixedId::SQIDS.encode([id])}"
|
|
13
|
+
Spree::Category.prefixed_id_for(product_category.category_id)
|
|
22
14
|
end
|
|
23
15
|
end
|
|
24
16
|
end
|
|
@@ -6,19 +6,11 @@ module Spree
|
|
|
6
6
|
collection_id: [:string, nullable: true]
|
|
7
7
|
|
|
8
8
|
attribute :product_id do |product_collection|
|
|
9
|
-
|
|
9
|
+
Spree::Product.prefixed_id_for(product_collection.product_id)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
attribute :collection_id do |product_collection|
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def prefixed_id_for(klass, id)
|
|
19
|
-
return nil if id.nil?
|
|
20
|
-
|
|
21
|
-
"#{klass._prefix_id_prefix}_#{Spree::PrefixedId::SQIDS.encode([id])}"
|
|
13
|
+
Spree::Collection.prefixed_id_for(product_collection.collection_id)
|
|
22
14
|
end
|
|
23
15
|
end
|
|
24
16
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V3
|
|
4
|
+
module Seller
|
|
5
|
+
# What a bulk product action did.
|
|
6
|
+
class BulkProductResultSerializer
|
|
7
|
+
include Alba::Resource
|
|
8
|
+
include Typelizer::DSL
|
|
9
|
+
|
|
10
|
+
typelize product_count: [:number, comment: 'Products the action applied to'],
|
|
11
|
+
skipped_count: [:number, optional: true, comment: 'Present only when something was skipped']
|
|
12
|
+
|
|
13
|
+
attributes :product_count
|
|
14
|
+
|
|
15
|
+
attribute :skipped_count, if: proc { |result| result.key?(:skipped_count) } do |result|
|
|
16
|
+
result[:skipped_count]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -31,9 +31,7 @@ module Spree
|
|
|
31
31
|
# Null until the parcel actually ships, which is most of its life.
|
|
32
32
|
typelize fulfilled_at: [:string, nullable: true]
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
fulfillment.fulfillment_type.presence || (fulfillment.digital? ? 'digital' : 'shipping')
|
|
36
|
-
end
|
|
34
|
+
attributes :fulfillment_type
|
|
37
35
|
|
|
38
36
|
# How it travels and where it leaves from, as names rather than
|
|
39
37
|
# expanded records: a seller reads them, never edits them here.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V3
|
|
4
|
+
module Seller
|
|
5
|
+
# The answer to a password reset request. It reads the same whether
|
|
6
|
+
# or not an account matched, so it reveals nothing about who exists.
|
|
7
|
+
class PasswordResetAcknowledgementSerializer
|
|
8
|
+
include Alba::Resource
|
|
9
|
+
include Typelizer::DSL
|
|
10
|
+
|
|
11
|
+
typelize message: :string
|
|
12
|
+
|
|
13
|
+
attributes :message
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V3
|
|
4
|
+
module Seller
|
|
5
|
+
# Where a seller sets up their payout account with the payout
|
|
6
|
+
# provider. Minted per request, so no id.
|
|
7
|
+
class PayoutAccountLinkSerializer
|
|
8
|
+
include Alba::Resource
|
|
9
|
+
include Typelizer::DSL
|
|
10
|
+
|
|
11
|
+
typelize url: [:string, nullable: true, comment: 'Null when the provider hosts no page to set the account up on']
|
|
12
|
+
|
|
13
|
+
attributes :url
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -8,11 +8,16 @@ module Spree
|
|
|
8
8
|
|
|
9
9
|
typelize address2: [:string, nullable: true], state_name: [:string, nullable: true],
|
|
10
10
|
phone: [:string, nullable: true], company: [:string, nullable: true],
|
|
11
|
+
admin_name: [:string, nullable: true],
|
|
11
12
|
active: :boolean, default: :boolean, kind: [:string, enum: Spree::StockLocation::KINDS, enum_type_name: 'StockLocationKind'],
|
|
12
|
-
|
|
13
|
+
backorderable_default: :boolean, propagate_all_variants: :boolean,
|
|
14
|
+
pickup_enabled: :boolean, returns_enabled: :boolean,
|
|
15
|
+
pickup_stock_policy: [:string, enum: Spree::StockLocation::PICKUP_STOCK_POLICIES, enum_type_name: 'PickupStockPolicy']
|
|
13
16
|
|
|
14
|
-
attributes :address2, :state_name, :phone, :company, :active, :default, :kind,
|
|
15
|
-
:
|
|
17
|
+
attributes :admin_name, :address2, :state_name, :phone, :company, :active, :default, :kind,
|
|
18
|
+
:backorderable_default, :propagate_all_variants,
|
|
19
|
+
:pickup_enabled, :pickup_stock_policy, :returns_enabled,
|
|
20
|
+
created_at: :iso8601, updated_at: :iso8601
|
|
16
21
|
end
|
|
17
22
|
end
|
|
18
23
|
end
|
|
@@ -178,7 +178,7 @@ module Spree
|
|
|
178
178
|
display_label = ov_translations[id] || label
|
|
179
179
|
|
|
180
180
|
{
|
|
181
|
-
id:
|
|
181
|
+
id: Spree::OptionValue.prefixed_id_for(id),
|
|
182
182
|
name: name,
|
|
183
183
|
label: display_label,
|
|
184
184
|
position: position,
|
|
@@ -212,10 +212,6 @@ module Spree
|
|
|
212
212
|
end
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
-
def encode_prefixed_id(prefix, id)
|
|
216
|
-
"#{prefix}_#{Spree::PrefixedId::SQIDS.encode([id])}"
|
|
217
|
-
end
|
|
218
|
-
|
|
219
215
|
# Returns the scope with all option type filters EXCEPT the given one applied.
|
|
220
216
|
# This gives disjunctive counts: selecting Blue still shows Red's true count.
|
|
221
217
|
def disjunctive_scope_for(option_type)
|
data/config/routes.rb
CHANGED
|
@@ -442,7 +442,9 @@ Spree::Core::Engine.add_routes do
|
|
|
442
442
|
resources :tax_rates, concerns: :custom_fieldable
|
|
443
443
|
|
|
444
444
|
# Selectable tax engines and their declared limits (discovery only)
|
|
445
|
-
resources :tax_providers, only: [:index]
|
|
445
|
+
resources :tax_providers, only: [:index] do
|
|
446
|
+
member { get :tax_codes }
|
|
447
|
+
end
|
|
446
448
|
# How sellers get paid. Discovery only — the choice itself is a store
|
|
447
449
|
# preference, so there is nothing here to create.
|
|
448
450
|
resources :payout_providers, only: [:index]
|
|
@@ -43,7 +43,11 @@ module Spree
|
|
|
43
43
|
invitation_acceptance_link role permission export saved_report import import_row import_mapping promotion
|
|
44
44
|
maintenance_task_run
|
|
45
45
|
promotion_action promotion_rule coupon_code price_adjustment_tier price_list price_rule
|
|
46
|
-
resource_translations
|
|
46
|
+
resource_translations translatable_resource translation_coverage
|
|
47
|
+
resource_type_definition payment_method_type integration_type_definition calculator_type
|
|
48
|
+
product_membership_result bulk_stock_level_result bulk_product_result setup_status
|
|
49
|
+
password_reset_acknowledgement integration_connection_result tag
|
|
50
|
+
email_template email_template_draft email_template_revision email_template_preview
|
|
47
51
|
email_template_sample_record file_upload file_upload_target].freeze
|
|
48
52
|
|
|
49
53
|
SELLER_SERIALIZERS =
|
|
@@ -52,7 +56,8 @@ module Spree
|
|
|
52
56
|
order_line_item fulfillment fulfillment_item delivery delivery_rate shipping_label return
|
|
53
57
|
return_line_item exchange exchange_line_item claim claim_line_item reason package_type stock_location
|
|
54
58
|
requirement_custom_field tax_identifier requirement_status import import_row import_mapping
|
|
55
|
-
requirement_submission export transfer payout
|
|
59
|
+
requirement_submission export transfer payout payout_account_link bulk_product_result
|
|
60
|
+
password_reset_acknowledgement balance payment_split price price_history file_upload digital_asset
|
|
56
61
|
file_upload_target store].freeze
|
|
57
62
|
|
|
58
63
|
INJECTION_POINTS_WITH_DEFAULTS = {
|
|
@@ -29,6 +29,11 @@ module Spree
|
|
|
29
29
|
}
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# A list that is not paginated
|
|
33
|
+
def list(items)
|
|
34
|
+
{ type: :object, properties: { data: { type: :array, items: items } }, required: %w[data] }
|
|
35
|
+
end
|
|
36
|
+
|
|
32
37
|
# Error response schema
|
|
33
38
|
def error_response
|
|
34
39
|
ref('ErrorResponse')
|
|
@@ -58,6 +63,10 @@ module Spree
|
|
|
58
63
|
}]
|
|
59
64
|
}.freeze
|
|
60
65
|
|
|
66
|
+
# What a `Record<string, …>` type may hold for its values to be documented.
|
|
67
|
+
PUBLISHED_TYPE_NAME = /\A[A-Z]\w*\z/
|
|
68
|
+
RECORD_VALUE_TYPES = %w[string number boolean].freeze
|
|
69
|
+
|
|
61
70
|
def common_schemas
|
|
62
71
|
{
|
|
63
72
|
PaginationMeta: {
|
|
@@ -175,6 +184,45 @@ module Spree
|
|
|
175
184
|
required: %w[token user]
|
|
176
185
|
}
|
|
177
186
|
|
|
187
|
+
# Written by hand: the payload is computed, so its serializer declares
|
|
188
|
+
# no types to generate from.
|
|
189
|
+
schemas[:ResourceTranslations] = {
|
|
190
|
+
type: :object,
|
|
191
|
+
description: "A record's translatable fields and their value in each locale",
|
|
192
|
+
properties: {
|
|
193
|
+
resource_id: { type: :string, example: 'prod_UkLWZg9DAJ' },
|
|
194
|
+
resource_type: { type: :string, example: 'product' },
|
|
195
|
+
translations: {
|
|
196
|
+
type: :object,
|
|
197
|
+
description: 'Keyed by locale. Each entry holds every field\'s translation, null where there is none, ' \
|
|
198
|
+
'and `translated_field_count`.',
|
|
199
|
+
additionalProperties: { type: :object, additionalProperties: true },
|
|
200
|
+
example: { de: { name: 'Espressomaschine', description: nil, translated_field_count: 1 } }
|
|
201
|
+
},
|
|
202
|
+
fields: {
|
|
203
|
+
type: :array,
|
|
204
|
+
description: 'The translatable fields and their value in the default locale. Present when reading a record.',
|
|
205
|
+
items: {
|
|
206
|
+
type: :object,
|
|
207
|
+
properties: {
|
|
208
|
+
key: { type: :string, example: 'name' },
|
|
209
|
+
type: { type: :string, example: 'string', description: 'How the field is edited: `string` or `html`' },
|
|
210
|
+
source: { type: :string, nullable: true, example: 'Espresso Machine' }
|
|
211
|
+
},
|
|
212
|
+
required: %w[key type source]
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
default_locale: { type: :string, example: 'en', description: 'Absent on nested `children`' },
|
|
216
|
+
supported_locales: { type: :array, items: { type: :string }, example: %w[en de], description: 'Absent on nested `children`' },
|
|
217
|
+
children: {
|
|
218
|
+
type: :array,
|
|
219
|
+
description: 'Nested translatable records, such as the option values of an option type',
|
|
220
|
+
items: { '$ref' => '#/components/schemas/ResourceTranslations' }
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
required: %w[resource_id resource_type translations]
|
|
224
|
+
}
|
|
225
|
+
|
|
178
226
|
begin
|
|
179
227
|
schemas.merge!(typelizer_schemas(:admin))
|
|
180
228
|
rescue StandardError => e
|
|
@@ -313,6 +361,7 @@ module Spree
|
|
|
313
361
|
schemas.each_value do |s|
|
|
314
362
|
s[:'x-typelizer'] = true
|
|
315
363
|
strip_null_from_enums(s)
|
|
364
|
+
patch_nullable_unions(s)
|
|
316
365
|
end
|
|
317
366
|
patch_typescript_only_types(schemas, writer_name)
|
|
318
367
|
patch_promotion_action_calculator(schemas)
|
|
@@ -344,10 +393,45 @@ module Spree
|
|
|
344
393
|
case type.delete_suffix(' | null')
|
|
345
394
|
when /\AArray<(string|number|boolean)>\z/ then { type: :array, items: { type: Regexp.last_match(1).to_sym } }
|
|
346
395
|
when /\AArray</ then { type: :array, items: { type: :object } }
|
|
396
|
+
when /\ARecord<string, (.+)>\z/ then record_schema(Regexp.last_match(1).split(' | '))
|
|
347
397
|
when 'any', 'unknown' then {}
|
|
348
398
|
end
|
|
349
399
|
end
|
|
350
400
|
|
|
401
|
+
# A map whose values are a published type keeps the link to it, so the
|
|
402
|
+
# reference documents what is under each key. A map of plain values
|
|
403
|
+
# stays the plain object Typelizer publishes.
|
|
404
|
+
def record_schema(value_types)
|
|
405
|
+
nullable = value_types.delete('null')
|
|
406
|
+
return unless value_types.any? { |type| type.match?(PUBLISHED_TYPE_NAME) } &&
|
|
407
|
+
value_types.all? { |type| RECORD_VALUE_TYPES.include?(type) || type.match?(PUBLISHED_TYPE_NAME) }
|
|
408
|
+
|
|
409
|
+
values = value_types.map { |type| RECORD_VALUE_TYPES.include?(type) ? { type: type.to_sym } : ref(type) }
|
|
410
|
+
value = values.one? ? values.first : { anyOf: values }
|
|
411
|
+
value = nullable_union(value[:anyOf] || [value]) if nullable
|
|
412
|
+
{ type: :object, additionalProperties: value }
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
# OpenAPI 3.0 reads `nullable` only beside a `type`, so null gets a
|
|
416
|
+
# branch of its own, as a nullable reference does.
|
|
417
|
+
def nullable_union(alternatives)
|
|
418
|
+
{ anyOf: [*alternatives, Typelizer::NullableReferences::NULL] }
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# Typelizer writes a nullable union (`string | number | null`) as
|
|
422
|
+
# `nullable` beside an untyped `anyOf`, which admits no null.
|
|
423
|
+
def patch_nullable_unions(schema)
|
|
424
|
+
case schema
|
|
425
|
+
when Hash
|
|
426
|
+
schema.each_value { |value| patch_nullable_unions(value) }
|
|
427
|
+
if schema[:anyOf] && schema[:nullable] && !schema.key?(:type)
|
|
428
|
+
documentation = schema.except(:anyOf, :nullable)
|
|
429
|
+
schema.replace(nullable_union(schema[:anyOf]).merge(documentation))
|
|
430
|
+
end
|
|
431
|
+
when Array then schema.each { |item| patch_nullable_unions(item) }
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
351
435
|
# The calculator's TypeScript type has another name than its component.
|
|
352
436
|
def patch_promotion_action_calculator(schemas)
|
|
353
437
|
action = schemas['PromotionAction'] || schemas[:PromotionAction]
|
|
@@ -355,7 +439,7 @@ module Spree
|
|
|
355
439
|
return unless props
|
|
356
440
|
|
|
357
441
|
key = props.key?('calculator') ? 'calculator' : :calculator
|
|
358
|
-
props[key] =
|
|
442
|
+
props[key] = Typelizer::NullableReferences.wrap(ref('PromotionActionCalculator')) if props[key]
|
|
359
443
|
end
|
|
360
444
|
|
|
361
445
|
# One component per subtype Spree ships (`PromotionRuleItemTotalPreferences`)
|
|
@@ -423,7 +507,7 @@ module Spree
|
|
|
423
507
|
return unless props
|
|
424
508
|
|
|
425
509
|
key = props.key?('calculator') ? 'calculator' : :calculator
|
|
426
|
-
props[key] =
|
|
510
|
+
props[key] = Typelizer::NullableReferences.wrap(ref('DeliveryMethodCalculator')) if props[key]
|
|
427
511
|
end
|
|
428
512
|
|
|
429
513
|
# Typelizer adds nil to enum arrays for nullable fields.
|
|
@@ -35,6 +35,13 @@ module Spree
|
|
|
35
35
|
# from its generated index, so that index re-exports these types too.
|
|
36
36
|
INDEX_EXPORT = "export type * from '../preferences'\n".freeze
|
|
37
37
|
|
|
38
|
+
# A serializer of a `types` list names `PreferenceSchema`, which Typelizer
|
|
39
|
+
# imports from the generated index like any other type.
|
|
40
|
+
SCHEMA_EXPORT = <<~TS.freeze
|
|
41
|
+
/** The JSON Schema of a type's `preferences`, as a `types` endpoint lists it. */
|
|
42
|
+
export type { PreferenceSchema } from '@spree/sdk-core'
|
|
43
|
+
TS
|
|
44
|
+
|
|
38
45
|
# @param root [Pathname] the monorepo root
|
|
39
46
|
# @return [void]
|
|
40
47
|
def write!(root)
|
|
@@ -63,6 +70,7 @@ module Spree
|
|
|
63
70
|
imports = resources.map { |family| "import type #{family} from './generated/#{family}'\n" }.join
|
|
64
71
|
parts = families.flat_map { |family, members| family_parts(family, members, resources.include?(family)) }
|
|
65
72
|
parts.unshift(NARROWED) if resources.any?
|
|
73
|
+
parts.unshift(SCHEMA_EXPORT)
|
|
66
74
|
parts.unshift(imports) if imports.present?
|
|
67
75
|
|
|
68
76
|
HEADER + parts.join("\n")
|
|
@@ -37,6 +37,86 @@ if ENV['OPENAPI'] == 'true'
|
|
|
37
37
|
# to match across machines.
|
|
38
38
|
JWT_SECRET = 'openapi-example-signing-secret'
|
|
39
39
|
|
|
40
|
+
class << self
|
|
41
|
+
# The steps below rewrite every committed row and reset id sequences, so
|
|
42
|
+
# they must never reach a development or production database. Both the
|
|
43
|
+
# running environment and the database must say test: DATABASE_URL can
|
|
44
|
+
# point a test run at any database, and a database that records no
|
|
45
|
+
# environment is refused rather than trusted.
|
|
46
|
+
def ensure_test_database!
|
|
47
|
+
raise "OpenAPI generation runs only in the test environment, not #{Rails.env}" unless Rails.env.test?
|
|
48
|
+
|
|
49
|
+
recorded = recorded_environment
|
|
50
|
+
return if recorded == 'test'
|
|
51
|
+
|
|
52
|
+
raise "OpenAPI generation runs only against a test database; this one records #{recorded.inspect}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Freezes the clock for the whole run, not only inside examples. The
|
|
56
|
+
# default store, its market and its channel are created once, in a
|
|
57
|
+
# `before(:all)`, which runs ahead of every per-example hook, so their
|
|
58
|
+
# timestamps used to be the moment the run started.
|
|
59
|
+
def freeze_clock
|
|
60
|
+
Object.new.extend(ActiveSupport::Testing::TimeHelpers).travel_to(FROZEN_TIME)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The same records stay in the test database from one run to the next,
|
|
64
|
+
# so on any run but the first they still carry the time the database was
|
|
65
|
+
# first used. Everything committed is stamped with the frozen instant.
|
|
66
|
+
def restamp_committed_records
|
|
67
|
+
connection = ActiveRecord::Base.connection
|
|
68
|
+
|
|
69
|
+
connection.tables.each do |table|
|
|
70
|
+
timestamps = connection.columns(table).map(&:name) & %w[created_at updated_at]
|
|
71
|
+
next if timestamps.empty?
|
|
72
|
+
|
|
73
|
+
arel_table = Arel::Table.new(table)
|
|
74
|
+
update = Arel::UpdateManager.new.table(arel_table).set(timestamps.map { |column| [arel_table[column], FROZEN_TIME] })
|
|
75
|
+
connection.update(update)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# A rolled-back transaction gives SQLite its ids back, so every example
|
|
80
|
+
# starts from the same primary keys. PostgreSQL sequences only ever
|
|
81
|
+
# advance, which made every prefixed id depend on how many records the
|
|
82
|
+
# earlier examples created and on how often the suite had run against
|
|
83
|
+
# the database. Setting each sequence back to the last committed row
|
|
84
|
+
# before an example gives both databases the same ids.
|
|
85
|
+
def rewind_primary_keys
|
|
86
|
+
connection = ActiveRecord::Base.connection
|
|
87
|
+
return unless connection.adapter_name.match?(/postg/i)
|
|
88
|
+
|
|
89
|
+
@rewind_sequences ||= rewind_sequences_statement(connection)
|
|
90
|
+
connection.execute(@rewind_sequences) if @rewind_sequences
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
# The environment Rails wrote into the database when it was set up.
|
|
96
|
+
def recorded_environment
|
|
97
|
+
connection = ActiveRecord::Base.connection
|
|
98
|
+
metadata_table = ActiveRecord::Base.internal_metadata_table_name
|
|
99
|
+
return unless connection.data_source_exists?(metadata_table)
|
|
100
|
+
|
|
101
|
+
metadata = Arel::Table.new(metadata_table)
|
|
102
|
+
connection.select_value(metadata.project(metadata[:value]).where(metadata[:key].eq('environment')))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The last committed id is read when the statement runs, not when it is
|
|
106
|
+
# built, so rows committed later in the run keep their ids.
|
|
107
|
+
def rewind_sequences_statement(connection)
|
|
108
|
+
calls = connection.tables.filter_map do |table|
|
|
109
|
+
primary_key, sequence = connection.pk_and_sequence_for(table)
|
|
110
|
+
next unless sequence
|
|
111
|
+
|
|
112
|
+
last_id = "(SELECT MAX(#{connection.quote_column_name(primary_key)}) FROM #{connection.quote_table_name(table)})"
|
|
113
|
+
"setval(#{connection.quote(sequence.to_s)}, COALESCE(#{last_id}, 1), #{last_id} IS NOT NULL)"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
"SELECT #{calls.join(', ')}" if calls.any?
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
40
120
|
# SecureRandom bypasses the global PRNG (it reads from the OS), so seeding
|
|
41
121
|
# alone leaves API keys, invitation tokens and JWT ids churning. These
|
|
42
122
|
# counter-backed replacements produce values with the right shape and
|
|
@@ -112,8 +192,15 @@ if ENV['OPENAPI'] == 'true'
|
|
|
112
192
|
SecureRandom.singleton_class.prepend(Spree::OpenAPIDeterminism::PredictableSecureRandom)
|
|
113
193
|
|
|
114
194
|
RSpec.configure do |config|
|
|
195
|
+
config.before(:suite) do
|
|
196
|
+
Spree::OpenAPIDeterminism.ensure_test_database!
|
|
197
|
+
Spree::OpenAPIDeterminism.freeze_clock
|
|
198
|
+
Spree::OpenAPIDeterminism.restamp_committed_records
|
|
199
|
+
end
|
|
200
|
+
|
|
115
201
|
config.before do
|
|
116
202
|
travel_to(Spree::OpenAPIDeterminism::FROZEN_TIME)
|
|
203
|
+
Spree::OpenAPIDeterminism.rewind_primary_keys
|
|
117
204
|
end
|
|
118
205
|
|
|
119
206
|
# Reset before each example rather than once for the run, so a value shown
|
|
@@ -2,6 +2,7 @@ require 'spree/api/testing_support/v3/base'
|
|
|
2
2
|
require 'spree/api/testing_support/agent_tools'
|
|
3
3
|
require 'spree/api/testing_support/deterministic_openapi'
|
|
4
4
|
require 'spree/api/testing_support/filter_parameters'
|
|
5
|
+
require 'spree/api/testing_support/response_schema'
|
|
5
6
|
require 'spree/api/testing_support/sdk_method'
|
|
6
7
|
|
|
7
8
|
module Spree
|
|
@@ -166,7 +167,7 @@ module Spree
|
|
|
166
167
|
# and in its Rakefile, `require 'spree/api/testing_support/openapi_tasks'`
|
|
167
168
|
# for `rake spree:openapi:generate`.
|
|
168
169
|
module Openapi
|
|
169
|
-
HELPERS = [RequestBody, FilterParameters, AdminScope, AdminOperation, AgentTools, SdkMethod].freeze
|
|
170
|
+
HELPERS = [RequestBody, ResponseSchema, FilterParameters, AdminScope, AdminOperation, AgentTools, SdkMethod].freeze
|
|
170
171
|
|
|
171
172
|
class << self
|
|
172
173
|
# @param config [RSpec::Core::Configuration]
|
|
@@ -14,6 +14,9 @@ unless Rake::Task.task_defined?('spree:openapi:generate')
|
|
|
14
14
|
task :generate do
|
|
15
15
|
pattern = ENV.fetch('PATTERN', 'spec/integration/**/*_spec.rb')
|
|
16
16
|
ENV['OPENAPI'] = 'true'
|
|
17
|
+
# Signed blob ids and file URLs in the examples are keyed on the app's
|
|
18
|
+
# secret, which `rails new` generates per dummy app.
|
|
19
|
+
ENV['SECRET_KEY_BASE'] = 'openapi-example-secret-key-base'
|
|
17
20
|
ruby '-S', 'rspec', '--pattern', pattern, '--format', 'Rswag::Specs::SwaggerFormatter', '--order', 'defined'
|
|
18
21
|
end
|
|
19
22
|
end
|