solidus_api 2.9.6 → 2.10.3

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -2
  3. data/app/controllers/spree/api/addresses_controller.rb +1 -1
  4. data/app/controllers/spree/api/base_controller.rb +10 -10
  5. data/app/controllers/spree/api/checkouts_controller.rb +4 -4
  6. data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
  7. data/app/controllers/spree/api/images_controller.rb +1 -1
  8. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  9. data/app/controllers/spree/api/option_types_controller.rb +1 -1
  10. data/app/controllers/spree/api/option_values_controller.rb +1 -1
  11. data/app/controllers/spree/api/orders_controller.rb +10 -5
  12. data/app/controllers/spree/api/payments_controller.rb +1 -1
  13. data/app/controllers/spree/api/product_properties_controller.rb +1 -1
  14. data/app/controllers/spree/api/properties_controller.rb +1 -1
  15. data/app/controllers/spree/api/resource_controller.rb +1 -1
  16. data/app/controllers/spree/api/return_authorizations_controller.rb +1 -1
  17. data/app/controllers/spree/api/shipments_controller.rb +1 -1
  18. data/app/controllers/spree/api/stock_items_controller.rb +1 -1
  19. data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
  20. data/app/controllers/spree/api/stores_controller.rb +1 -1
  21. data/app/controllers/spree/api/taxonomies_controller.rb +4 -2
  22. data/app/controllers/spree/api/taxons_controller.rb +1 -1
  23. data/app/controllers/spree/api/variants_controller.rb +1 -1
  24. data/app/controllers/spree/api/zones_controller.rb +1 -1
  25. data/app/helpers/spree/api/api_helpers.rb +2 -2
  26. data/app/views/spree/api/images/_image.json.jbuilder +2 -2
  27. data/app/views/spree/api/orders/_order.json.jbuilder +1 -1
  28. data/app/views/spree/api/shared/_pagination.json.jbuilder +1 -1
  29. data/lib/spree/api.rb +0 -7
  30. data/lib/spree/api/config.rb +9 -0
  31. data/lib/spree/api/engine.rb +4 -4
  32. data/lib/spree/api/responders.rb +3 -2
  33. data/lib/spree/api/responders/{rabl_template.rb → jbuilder_template.rb} +3 -1
  34. data/{app/models → lib}/spree/api_configuration.rb +0 -0
  35. data/openapi/.stoplight.yml +7 -0
  36. data/openapi/api.oas2.yml +6108 -0
  37. data/openapi/authentication.md +25 -0
  38. data/openapi/checkout-flow.md +50 -0
  39. data/openapi/errors.md +3 -0
  40. data/openapi/lint.yml +1 -0
  41. data/openapi/main.hub.yml +65 -0
  42. data/openapi/pagination.md +7 -0
  43. data/openapi/theme.css +0 -0
  44. data/solidus_api.gemspec +1 -1
  45. data/spec/controllers/spree/api/resource_controller_spec.rb +4 -4
  46. data/spec/lib/spree_api_responders_spec.rb +10 -0
  47. data/spec/requests/api/address_books_spec.rb +2 -2
  48. data/spec/requests/{rabl_cache_spec.rb → jbuilder_cache_spec.rb} +2 -2
  49. data/spec/requests/spree/api/checkouts_controller_spec.rb +2 -2
  50. data/spec/requests/spree/api/classifications_controller_spec.rb +1 -1
  51. data/spec/requests/spree/api/option_types_controller_spec.rb +2 -2
  52. data/spec/requests/spree/api/option_values_controller_spec.rb +2 -2
  53. data/spec/requests/spree/api/orders_controller_spec.rb +15 -15
  54. data/spec/requests/spree/api/payments_controller_spec.rb +3 -3
  55. data/spec/requests/spree/api/products_controller_spec.rb +6 -6
  56. data/spec/requests/spree/api/stock_items_controller_spec.rb +5 -5
  57. data/spec/requests/spree/api/stock_locations_controller_spec.rb +4 -4
  58. data/spec/requests/spree/api/taxons_controller_spec.rb +2 -2
  59. metadata +25 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9041e899f4cd40c0426851ecab468e5b0e6799979026651d90ed71c68e9a33d2
4
- data.tar.gz: 6b6195d91d485815fc3e609c661efa408146b7ab49296c8db33987e568916ee4
3
+ metadata.gz: 5c84c03d908227e7072721b7a0a268e296c85606bd4b8f08dc538e052e6d8393
4
+ data.tar.gz: 3d4dcc56d49982aa91a6f73d86ac9ed6db4689c4e9b8a5e3fdfe846b91f94c57
5
5
  SHA512:
6
- metadata.gz: 72241153b2007035f40f1869e76a276597580d11fe4d8b24bd37529a03520f799edfd9530a18677df79aeaafffa8f929d1f2bae1b9a320871b781b705c21a2f5
7
- data.tar.gz: dcb64f63cb2edd713a03bb3c971ed9de693d4e1af34bb3cb5746ed73b2294660ddb3805382587f10675f2ec71642ebb79f979373b21b7f03af8157bde6250067
6
+ metadata.gz: 820e2d062e1ef2799bb70d5e67a25913ea0bfd0369a7934e6d22fe986a92a769b9a9b647f44f29842d34dec0f75988cf4172cf2ea5f41e30e2c866998718f45c
7
+ data.tar.gz: d53e4197d27d38b015146a71566a42b2e916134647fc4017ebdd123144bfd721b09897f40e67816d643d1f5fc2d1db2c1c074a35576a32d061fb3998c92aede1
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # solidus\_api
1
+ # solidus_api
2
2
 
3
- API contains the controllers and rabl views implementing the REST API of Solidus.
3
+ API contains the controllers and Jbuilder views implementing the REST API of
4
+ Solidus.
4
5
 
5
6
  ## Testing
6
7
 
@@ -9,3 +10,35 @@ Run the API tests:
9
10
  ```bash
10
11
  bundle exec rspec
11
12
  ```
13
+
14
+ ## Documentation
15
+
16
+ The API documentation is in the [openapi][docs-dir] directory. It follows the
17
+ OpenAPI specification and it is hosted on [Stoplight Docs][live-docs].
18
+
19
+ If you want to contribute, you can use [Stoplight Studio][studio]. Simply
20
+ follow these steps:
21
+
22
+ 1. Create a new Stoplight Studio project
23
+ 2. Copy-paste the content of `openapi/api.oas2.yml` into your project
24
+ 3. Edit the endpoints and models as needed
25
+ 4. Copy-paste the result back into `openapi/api.oas2.yml`
26
+ 5. Open a PR!
27
+
28
+ **Note: Only use embedded models in Stoplight Studio, as Stoplight Docs is
29
+ not compatible with externally-defined models!**
30
+
31
+ CircleCI automatically syncs our Git repo with Stoplight Docs when a PR is
32
+ merged, and automatically publishes a new version on Docs when a new Solidus
33
+ version is released.
34
+
35
+ ## Related projects
36
+
37
+ - [solidus-sdk](https://gitlab.com/deseretbook/packages/solidus-sdk): created
38
+ by Joel Saupe at [Deseret Book](https://deseretbook.com/), this is a JS SDK
39
+ that allows you to use the Solidus API. It even supports plug-ins, so you can
40
+ easily extend it with the endpoints provided by your Solidus extensions!
41
+
42
+ [docs-dir]: https://github.com/solidusio/solidus/tree/master/api/openapi
43
+ [live-docs]: https://solidus.docs.stoplight.io
44
+ [studio]: https://stoplight.io/p/studio
@@ -15,7 +15,7 @@ module Spree
15
15
  authorize! :update, @order, order_token
16
16
  find_address
17
17
 
18
- if @order.update_attributes({ "#{@order_source}_attributes" => address_params })
18
+ if @order.update({ "#{@order_source}_attributes" => address_params })
19
19
  @address = @order.send(@order_source)
20
20
  respond_with(@address, default_template: :show)
21
21
  else
@@ -49,9 +49,9 @@ module Spree
49
49
  def authenticate_user
50
50
  unless @current_api_user
51
51
  if requires_authentication? && api_key.blank? && order_token.blank?
52
- render "spree/api/errors/must_specify_api_key", status: 401
52
+ render "spree/api/errors/must_specify_api_key", status: :unauthorized
53
53
  elsif order_token.blank? && (requires_authentication? || api_key.present?)
54
- render "spree/api/errors/invalid_api_key", status: 401
54
+ render "spree/api/errors/invalid_api_key", status: :unauthorized
55
55
  end
56
56
  end
57
57
  end
@@ -65,7 +65,7 @@ module Spree
65
65
  end
66
66
 
67
67
  def unauthorized
68
- render "spree/api/errors/unauthorized", status: 401
68
+ render "spree/api/errors/unauthorized", status: :unauthorized
69
69
  end
70
70
 
71
71
  def gateway_error(exception)
@@ -78,7 +78,7 @@ module Spree
78
78
  exception: exception.message,
79
79
  error: exception.message,
80
80
  missing_param: exception.param
81
- }, status: 422
81
+ }, status: :unprocessable_entity
82
82
  end
83
83
 
84
84
  def requires_authentication?
@@ -86,7 +86,7 @@ module Spree
86
86
  end
87
87
 
88
88
  def not_found
89
- render "spree/api/errors/not_found", status: 404
89
+ render "spree/api/errors/not_found", status: :not_found
90
90
  end
91
91
 
92
92
  def current_ability
@@ -96,7 +96,7 @@ module Spree
96
96
  def invalid_resource!(resource)
97
97
  Rails.logger.error "invalid_resouce_errors=#{resource.errors.full_messages}"
98
98
  @resource = resource
99
- render "spree/api/errors/invalid_resource", status: 422
99
+ render "spree/api/errors/invalid_resource", status: :unprocessable_entity
100
100
  end
101
101
 
102
102
  def api_key
@@ -112,7 +112,7 @@ module Spree
112
112
 
113
113
  def spree_token
114
114
  token = request.headers["X-Spree-Token"]
115
- return unless token.present?
115
+ return if token.blank?
116
116
 
117
117
  Spree::Deprecation.warn(
118
118
  'The custom X-Spree-Token request header is deprecated and will be removed in the next release.' \
@@ -164,8 +164,8 @@ module Spree
164
164
 
165
165
  def lock_order
166
166
  OrderMutex.with_lock!(@order) { yield }
167
- rescue Spree::OrderMutex::LockFailed => e
168
- render plain: e.message, status: 409
167
+ rescue Spree::OrderMutex::LockFailed => error
168
+ render plain: error.message, status: :conflict
169
169
  end
170
170
 
171
171
  def insufficient_stock_error(exception)
@@ -175,7 +175,7 @@ module Spree
175
175
  errors: [I18n.t(:quantity_is_not_available, scope: "spree.api.order")],
176
176
  type: 'insufficient_stock'
177
177
  },
178
- status: 422
178
+ status: :unprocessable_entity
179
179
  )
180
180
  end
181
181
 
@@ -23,8 +23,8 @@ module Spree
23
23
  authorize! :update, @order, order_token
24
24
  @order.next!
25
25
  respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
26
- rescue StateMachines::InvalidTransition => e
27
- logger.error("invalid_transition #{e.event} from #{e.from} for #{e.object.class.name}. Error: #{e.inspect}")
26
+ rescue StateMachines::InvalidTransition => error
27
+ logger.error("invalid_transition #{error.event} from #{error.from} for #{error.object.class.name}. Error: #{error.inspect}")
28
28
  respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
29
29
  end
30
30
 
@@ -42,8 +42,8 @@ module Spree
42
42
  @order.complete!
43
43
  respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
44
44
  end
45
- rescue StateMachines::InvalidTransition => e
46
- logger.error("invalid_transition #{e.event} from #{e.from} for #{e.object.class.name}. Error: #{e.inspect}")
45
+ rescue StateMachines::InvalidTransition => error
46
+ logger.error("invalid_transition #{error.event} from #{error.from} for #{error.object.class.name}. Error: #{error.inspect}")
47
47
  respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
48
48
  end
49
49
 
@@ -18,7 +18,7 @@ module Spree
18
18
  end
19
19
 
20
20
  def update
21
- if @credit_card.update_attributes(credit_card_update_params)
21
+ if @credit_card.update(credit_card_update_params)
22
22
  respond_with(@credit_card, default_template: :show)
23
23
  else
24
24
  invalid_resource!(@credit_card)
@@ -21,7 +21,7 @@ module Spree
21
21
 
22
22
  def update
23
23
  @image = Spree::Image.accessible_by(current_ability, :update).find(params[:id])
24
- @image.update_attributes(image_params)
24
+ @image.update(image_params)
25
25
  respond_with(@image, default_template: :show)
26
26
  end
27
27
 
@@ -14,7 +14,7 @@ module Spree
14
14
  authorize! :update, inventory_unit.order
15
15
 
16
16
  inventory_unit.transaction do
17
- if inventory_unit.update_attributes(inventory_unit_params)
17
+ if inventory_unit.update(inventory_unit_params)
18
18
  fire
19
19
  render :show, status: 200
20
20
  else
@@ -29,7 +29,7 @@ module Spree
29
29
 
30
30
  def update
31
31
  @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
32
- if @option_type.update_attributes(option_type_params)
32
+ if @option_type.update(option_type_params)
33
33
  render :show
34
34
  else
35
35
  invalid_resource!(@option_type)
@@ -29,7 +29,7 @@ module Spree
29
29
 
30
30
  def update
31
31
  @option_value = scope.accessible_by(current_ability, :update).find(params[:id])
32
- if @option_value.update_attributes(option_value_params)
32
+ if @option_value.update(option_value_params)
33
33
  render :show
34
34
  else
35
35
  invalid_resource!(@option_value)
@@ -55,10 +55,9 @@ module Spree
55
55
  def index
56
56
  authorize! :index, Order
57
57
  orders_includes = [
58
- :user,
59
- :payments,
60
- :adjustments,
61
- :line_items
58
+ { user: :store_credits },
59
+ :line_items,
60
+ :valid_store_credit_payments
62
61
  ]
63
62
  @orders = paginate(
64
63
  Spree::Order
@@ -174,7 +173,13 @@ module Spree
174
173
  end
175
174
 
176
175
  def find_order(_lock = false)
177
- @order = Spree::Order.find_by!(number: params[:id])
176
+ @order = Spree::Order.
177
+ includes(line_items: [:adjustments, { variant: :images }],
178
+ payments: :payment_method,
179
+ shipments: {
180
+ shipping_rates: { shipping_method: :zones, taxes: :tax_rate }
181
+ }).
182
+ find_by!(number: params[:id])
178
183
  end
179
184
 
180
185
  def order_id
@@ -31,7 +31,7 @@ module Spree
31
31
  authorize! params[:action], @payment
32
32
  if !@payment.pending?
33
33
  render 'update_forbidden', status: 403
34
- elsif @payment.update_attributes(payment_params)
34
+ elsif @payment.update(payment_params)
35
35
  respond_with(@payment, default_template: :show)
36
36
  else
37
37
  invalid_resource!(@payment)
@@ -38,7 +38,7 @@ module Spree
38
38
  def update
39
39
  if @product_property
40
40
  authorize! :update, @product_property
41
- @product_property.update_attributes(product_property_params)
41
+ @product_property.update(product_property_params)
42
42
  respond_with(@product_property, status: 200, default_template: :show)
43
43
  else
44
44
  invalid_resource!(@product_property)
@@ -39,7 +39,7 @@ module Spree
39
39
  def update
40
40
  if @property
41
41
  authorize! :update, @property
42
- @property.update_attributes(property_params)
42
+ @property.update(property_params)
43
43
  respond_with(@property, status: 200, default_template: :show)
44
44
  else
45
45
  invalid_resource!(@property)
@@ -43,7 +43,7 @@ class Spree::Api::ResourceController < Spree::Api::BaseController
43
43
  def update
44
44
  authorize! :update, @object
45
45
 
46
- if @object.update_attributes(permitted_resource_params)
46
+ if @object.update(permitted_resource_params)
47
47
  respond_with(@object, status: 200, default_template: :show)
48
48
  else
49
49
  invalid_resource!(@object)
@@ -50,7 +50,7 @@ module Spree
50
50
 
51
51
  def update
52
52
  @return_authorization = @order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
53
- if @return_authorization.update_attributes(return_authorization_params)
53
+ if @return_authorization.update(return_authorization_params)
54
54
  respond_with(@return_authorization, default_template: :show)
55
55
  else
56
56
  invalid_resource!(@return_authorization)
@@ -146,7 +146,7 @@ module Spree
146
146
  end
147
147
 
148
148
  def update_shipment
149
- @shipment.update_attributes(shipment_params)
149
+ @shipment.update(shipment_params)
150
150
  @shipment.reload
151
151
  end
152
152
 
@@ -40,7 +40,7 @@ module Spree
40
40
  adjustment -= @stock_item.count_on_hand if params[:stock_item][:force]
41
41
 
42
42
  Spree::StockItem.transaction do
43
- if @stock_item.update_attributes(stock_item_params)
43
+ if @stock_item.update(stock_item_params)
44
44
  adjust_stock_item_count_on_hand(adjustment)
45
45
  respond_with(@stock_item, status: 200, default_template: :show)
46
46
  else
@@ -33,7 +33,7 @@ module Spree
33
33
 
34
34
  def update
35
35
  authorize! :update, stock_location
36
- if stock_location.update_attributes(stock_location_params)
36
+ if stock_location.update(stock_location_params)
37
37
  respond_with(stock_location, status: 200, default_template: :show)
38
38
  else
39
39
  invalid_resource!(stock_location)
@@ -24,7 +24,7 @@ module Spree
24
24
 
25
25
  def update
26
26
  authorize! :update, @store
27
- if @store.update_attributes(store_params)
27
+ if @store.update(store_params)
28
28
  respond_with(@store, status: 200, default_template: :show)
29
29
  else
30
30
  invalid_resource!(@store)
@@ -33,7 +33,7 @@ module Spree
33
33
 
34
34
  def update
35
35
  authorize! :update, taxonomy
36
- if taxonomy.update_attributes(taxonomy_params)
36
+ if taxonomy.update(taxonomy_params)
37
37
  respond_with(taxonomy, status: 200, default_template: :show)
38
38
  else
39
39
  invalid_resource!(taxonomy)
@@ -58,7 +58,9 @@ module Spree
58
58
  end
59
59
 
60
60
  def taxonomy
61
- @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:id])
61
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).
62
+ includes(root: :children).
63
+ find(params[:id])
62
64
  end
63
65
 
64
66
  def taxonomy_params
@@ -56,7 +56,7 @@ module Spree
56
56
 
57
57
  def update
58
58
  authorize! :update, taxon
59
- if taxon.update_attributes(taxon_params)
59
+ if taxon.update(taxon_params)
60
60
  respond_with(taxon, status: 200, default_template: :show)
61
61
  else
62
62
  invalid_resource!(taxon)
@@ -43,7 +43,7 @@ module Spree
43
43
 
44
44
  def update
45
45
  @variant = scope.accessible_by(current_ability, :update).find(params[:id])
46
- if @variant.update_attributes(variant_params)
46
+ if @variant.update(variant_params)
47
47
  respond_with(@variant, status: 200, default_template: :show)
48
48
  else
49
49
  invalid_resource!(@product)
@@ -37,7 +37,7 @@ module Spree
37
37
 
38
38
  def update
39
39
  authorize! :update, zone
40
- if zone.update_attributes(zone_params)
40
+ if zone.update(zone_params)
41
41
  respond_with(zone, status: 200, default_template: :show)
42
42
  else
43
43
  invalid_resource!(zone)
@@ -40,7 +40,7 @@ module Spree
40
40
 
41
41
  def required_fields_for(model)
42
42
  required_fields = model._validators.select do |_field, validations|
43
- validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
43
+ validations.any? { |validation| validation.is_a?(ActiveModel::Validations::PresenceValidator) }
44
44
  end.map(&:first) # get fields that are invalid
45
45
  # Permalinks presence is validated, but are really automatically generated
46
46
  # Therefore we shouldn't tell API clients that they MUST send one through
@@ -177,7 +177,7 @@ module Spree
177
177
  ]
178
178
 
179
179
  def variant_attributes
180
- if @current_user_roles && @current_user_roles.include?("admin")
180
+ if @current_user_roles&.include?("admin")
181
181
  @@variant_attributes + [:cost_price]
182
182
  else
183
183
  @@variant_attributes
@@ -2,6 +2,6 @@
2
2
 
3
3
  json.(image, *image_attributes)
4
4
  json.(image, :viewable_type, :viewable_id)
5
- Spree::Image.attachment_definitions[:attachment][:styles].each do |k, _v|
6
- json.set! "#{k}_url", image.attachment.url(k)
5
+ Spree::Image.attachment_definitions[:attachment][:styles].each do |key, _value|
6
+ json.set! "#{key}_url", image.attachment.url(key)
7
7
  end
@@ -3,7 +3,7 @@
3
3
  json.cache! [I18n.locale, order] do
4
4
  json.(order, *order_attributes)
5
5
  json.display_item_total(order.display_item_total.to_s)
6
- json.total_quantity(order.line_items.sum(:quantity))
6
+ json.total_quantity(order.line_items.to_a.sum(&:quantity))
7
7
  json.display_total(order.display_total.to_s)
8
8
  json.display_ship_total(order.display_ship_total)
9
9
  json.display_tax_total(order.display_tax_total)
@@ -4,4 +4,4 @@ json.count pagination.count
4
4
  json.total_count pagination.total_count
5
5
  json.current_page pagination.current_page
6
6
  json.pages pagination.total_pages
7
- json.per_page pagination.current_per_page
7
+ json.per_page pagination.limit_value
@@ -2,11 +2,4 @@
2
2
 
3
3
  require 'spree/core'
4
4
 
5
- require 'responders'
6
-
7
- module Spree
8
- module Api
9
- end
10
- end
11
-
12
5
  require 'spree/api/engine'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spree/api_configuration'
4
+
5
+ module Spree
6
+ module Api
7
+ Config = Spree::ApiConfiguration.new
8
+ end
9
+ end