Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JR isn't letting me send meta as a record property, despite it allows in jsonapi.org #1040

Open
krainboltgreene opened this issue Apr 20, 2017 · 3 comments

Comments

@krainboltgreene
Copy link

Data:

> POST /v1/ayments HTTP/1.1
> Host: commerce.laurelandwolf.local
> Accept-Encoding: deflate, gzip
> Content-Type: application/vnd.api+json
> Accept: application/vnd.api+json
> Content-Length: 364
| {
| 	"data": {
| 		"type": "payments",
| 		"attributes": {
| 			"token": "tok_visa"
| 		},
| 		"relationships": {
| 			"chargeable": {
| 				"data": {
| 					"id": "1",
| 					"type": "requests"
| 				}
| 			}
| 		},
| 		"meta": {
| 			"request": {
| 				"shipping-cents": 10000,
| 				"shipping-currency": "USD"
| 			}
| 		}
| 	}
| }

Response:

{
	"errors": [
		{
			"title": "Param not allowed",
			"detail": "meta is not allowed.",
			"code": "105",
			"status": "400"
		}
	]
}

jsonapi.org specification:

Creating Resources

A resource can be created by sending a POST request to a URL that represents a collection of resources. The request MUST include a single resource object as primary data. The resource object MUST contain at least a type member.

Resource Objects

"Resource objects" appear in a JSON API document to represent resources.

A resource object MUST contain at least the following top-level members:

  • id
  • type

Exception: The id member is not required when the resource object originates at
the client and represents a new resource to be created on the server.

In addition, a resource object MAY contain any of these top-level members:

  • attributes: an [attributes object][attributes] representing some of the resource's data.
  • relationships: a [relationships object][relationships] describing relationships between
    the resource and other JSON API resources.
  • links: a [links object][links] containing links related to the resource.
  • meta: a [meta object][meta] containing non-standard meta-information about a
    resource that can not be represented as an attribute or relationship.
@lgebhardt
Copy link
Member

Yes, we should allow this to be sent and provide a way to access the data.

@kevintraver
Copy link
Contributor

kevintraver commented Jul 30, 2019

Is it possible to access the meta object on the resource itself once it is allowed as a verified param?

@kevintraver
Copy link
Contributor

I think the first step would be allowing in verify_permitted_params

verify_permitted_params(params, allowed_fields)

def verify_permitted_params(params, allowed_fields)
...
  when 'type'
  when 'meta'
  when 'id'
...
end

Then returning meta with parse_params

'to_one' => checked_to_one_relationships,

return {
  'attributes' => checked_attributes,
  'meta' => checked_meta,
  'to_one' => checked_to_one_relationships,
  'to_many' => checked_to_many_relationships
}.deep_transform_keys { |key| unformat_key(key) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants