jpie 4.3.0 → 4.4.0
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/CHANGELOG.md +24 -0
- data/README.md +1 -0
- data/lib/json_api/controllers/concerns/resource_actions/document_validation.rb +38 -0
- data/lib/json_api/controllers/concerns/resource_actions/type_validation.rb +2 -1
- data/lib/json_api/controllers/concerns/resource_actions.rb +4 -0
- data/lib/json_api/controllers/relationships_controller.rb +1 -0
- data/lib/json_api/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68b78d7b1a591c1ea4d42aa885e7ba37e1bf494e96a6c214bb8d8a99e3395769
|
|
4
|
+
data.tar.gz: 84b4a609454016f97cc9a9dac08de5d8ff674e7b7dd6799df51aa599dd6bfae0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10decee75897b487367f1b0996d6f6bb7e179451ddc9a4724d1531a1c0364119fb5d223d0aef1614c6d446a71d78bbde92a4158086332290ca714b9c9fe2744a
|
|
7
|
+
data.tar.gz: 5ccbf2551f2b85d128b9b5e199f41b275eb610af785a18a4a433003241397ce13e8b9df875a4087ba5c0e6c1dc3bada24017419e5d2189e12ca5693748a69330
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,30 @@ at release time.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.4.0] - 2026-11-25
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **Refuse a resource request whose `data` or `relationships` is no object.**
|
|
15
|
+
A POST, PATCH or DELETE of one resource now answers 400
|
|
16
|
+
(`parameter_not_allowed`) when `data` is a list or a scalar. It also answers
|
|
17
|
+
400 when `relationships` is not an object. The detail is "data must be a JSON
|
|
18
|
+
object" or "relationships must be a JSON object". The check runs before the
|
|
19
|
+
other resource callbacks of jpie. A host callback that read such a body with
|
|
20
|
+
`raw_jsonapi_data`, or dug into `relationships`, raised, so the request
|
|
21
|
+
answered 500. A DELETE with such a body ran before; it now answers 400 and
|
|
22
|
+
deletes nothing. A DELETE with no `data`, or with an object body, behaves as
|
|
23
|
+
before. `/<type>/<id>/relationships/<name>` still takes a list `data`. A route
|
|
24
|
+
that `jsonapi_resources` did not draw is not checked.
|
|
25
|
+
**Upgrade:** a client that sends a list body on a resource DELETE gets 400.
|
|
26
|
+
Regression spec: `non_object_resource_data_spec.rb`.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- **Read `relationship_name` from the route only.** A `?relationship_name=`
|
|
31
|
+
query parameter on a resource PATCH or POST skipped the type check. So a
|
|
32
|
+
PATCH of `/posts/1` with `type: "users"` saved the post. It now answers 409.
|
|
33
|
+
|
|
10
34
|
## [4.3.0] - 2026-11-25
|
|
11
35
|
|
|
12
36
|
### Fixed
|
data/README.md
CHANGED
|
@@ -1275,6 +1275,7 @@ The gem validates relationship data:
|
|
|
1275
1275
|
- Invalid relationship type (for non-polymorphic associations) returns `400 Bad Request`
|
|
1276
1276
|
- Invalid polymorphic type (class doesn't exist) returns `400 Bad Request`
|
|
1277
1277
|
- Attempting to unset linkage that cannot be nullified (e.g., foreign key has NOT NULL constraint) returns `400 Bad Request`
|
|
1278
|
+
- A POST, PATCH or DELETE of one resource whose `data` is not an object, or whose `relationships` is not an object, returns `400 Bad Request` before any other callback reads the body. A relationship endpoint still takes a list `data`.
|
|
1278
1279
|
|
|
1279
1280
|
## Relationship Endpoint Details
|
|
1280
1281
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module JSONAPI
|
|
4
|
+
module ResourceActions
|
|
5
|
+
# A resource request carries one resource object in `data`, and the object carries its
|
|
6
|
+
# relationships as an object. The check runs before the other resource callbacks of jpie.
|
|
7
|
+
# So no later callback of jpie or of the host reads a list or a scalar as an object.
|
|
8
|
+
# A relationship endpoint takes a list `data` by design and keeps its own checks.
|
|
9
|
+
# A route that names no resource type is not a jpie resource route, so the check skips it.
|
|
10
|
+
# The check reads both route members from the path, because a query string can set them too.
|
|
11
|
+
module DocumentValidation
|
|
12
|
+
extend ActiveSupport::Concern
|
|
13
|
+
|
|
14
|
+
def validate_resource_document!
|
|
15
|
+
return if request.path_parameters[:resource_type].blank?
|
|
16
|
+
return if request.path_parameters[:relationship_name].present?
|
|
17
|
+
|
|
18
|
+
data = params[:data]
|
|
19
|
+
return if data.nil?
|
|
20
|
+
|
|
21
|
+
member = non_object_member(data)
|
|
22
|
+
return unless member
|
|
23
|
+
|
|
24
|
+
error = JSONAPI::Errors::ParameterNotAllowed.new(["#{member} must be a JSON object"])
|
|
25
|
+
render_parameter_not_allowed_error(error)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def non_object_member(data)
|
|
31
|
+
return "data" unless data.is_a?(ActionController::Parameters)
|
|
32
|
+
|
|
33
|
+
relationships = data[:relationships]
|
|
34
|
+
"relationships" unless relationships.nil? || relationships.is_a?(ActionController::Parameters)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -7,7 +7,8 @@ module JSONAPI
|
|
|
7
7
|
|
|
8
8
|
def validate_resource_type!
|
|
9
9
|
return unless @resource_class
|
|
10
|
-
|
|
10
|
+
# Read the route, not params: a query string can set relationship_name too.
|
|
11
|
+
return if request.path_parameters[:relationship_name].present?
|
|
11
12
|
|
|
12
13
|
requested = jsonapi_type
|
|
13
14
|
expected = resource_type
|
|
@@ -8,6 +8,7 @@ require_relative "resource_actions/include_preloading"
|
|
|
8
8
|
require_relative "resource_actions/serialization"
|
|
9
9
|
require_relative "resource_actions/pagination"
|
|
10
10
|
require_relative "resource_actions/type_validation"
|
|
11
|
+
require_relative "resource_actions/document_validation"
|
|
11
12
|
require_relative "resource_actions/crud_helpers"
|
|
12
13
|
require_relative "resource_actions/resource_loading"
|
|
13
14
|
|
|
@@ -21,10 +22,13 @@ module JSONAPI
|
|
|
21
22
|
include Serialization
|
|
22
23
|
include Pagination
|
|
23
24
|
include TypeValidation
|
|
25
|
+
include DocumentValidation
|
|
24
26
|
include CrudHelpers
|
|
25
27
|
include ResourceLoading
|
|
26
28
|
|
|
27
29
|
included do
|
|
30
|
+
# First, so no later callback reads a body that holds no resource object.
|
|
31
|
+
before_action :validate_resource_document!, only: %i[create update destroy]
|
|
28
32
|
before_action :load_jsonapi_resource_class
|
|
29
33
|
# A query parameter shapes the query the loader builds, so judge every one of them
|
|
30
34
|
# before the loader reads the database. The body members stay after the load,
|
|
@@ -19,6 +19,7 @@ module JSONAPI
|
|
|
19
19
|
|
|
20
20
|
skip_before_action :validate_resource_type!, only: %i[update destroy]
|
|
21
21
|
skip_before_action :validate_resource_id!, only: %i[update destroy]
|
|
22
|
+
skip_before_action :validate_resource_document!, only: %i[update destroy]
|
|
22
23
|
|
|
23
24
|
# A polymorphic or namespaced relationship can only learn at serialization
|
|
24
25
|
# that the request namespace carries no resource for the record's class.
|
data/lib/json_api/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jpie
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emil Kampp
|
|
@@ -117,6 +117,7 @@ files:
|
|
|
117
117
|
- lib/json_api/controllers/concerns/relationships/updating.rb
|
|
118
118
|
- lib/json_api/controllers/concerns/resource_actions.rb
|
|
119
119
|
- lib/json_api/controllers/concerns/resource_actions/crud_helpers.rb
|
|
120
|
+
- lib/json_api/controllers/concerns/resource_actions/document_validation.rb
|
|
120
121
|
- lib/json_api/controllers/concerns/resource_actions/field_validation.rb
|
|
121
122
|
- lib/json_api/controllers/concerns/resource_actions/filter_validation.rb
|
|
122
123
|
- lib/json_api/controllers/concerns/resource_actions/include_preloading.rb
|