Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 05 20:44

    remear on master

    Change how renderer output is c… Add render jsonapi specs that c… Add minor improvements to dev e… and 2 more (compare)

  • Oct 05 20:44
    remear closed #133
  • Oct 05 20:44
    remear commented #133
  • Oct 05 20:27
    malcolmbaig opened #133
  • Oct 05 17:40

    remear on omit-relationship-meta-when-nil

    (compare)

  • Oct 05 17:40

    remear on master

    Omit relationship meta when nil… (compare)

  • Oct 05 17:40
    remear closed #121
  • Oct 05 17:34
    remear opened #121
  • Oct 05 17:31

    remear on omit-relationship-meta-when-nil

    Omit relationship meta when nil (compare)

  • Oct 05 17:30

    remear on omit-relationship-meta-when-nil

    (compare)

  • Oct 05 16:49

    remear on guard-bad-content-type

    (compare)

  • Oct 05 16:48

    remear on master

    Guard valid content type check … (compare)

  • Oct 05 16:48
    remear closed #132
  • Oct 05 16:42
    remear opened #132
  • Oct 05 15:58

    remear on guard-bad-content-type

    Guard valid content type check … (compare)

  • Sep 08 08:39
    dawidof closed #126
  • Sep 08 08:39
    dawidof commented #126
  • Sep 08 08:39

    dawidof on master

    Bump sqlite3 version Use active record error attribu… Bump version and 2 more (compare)

  • Sep 08 08:39
    dawidof closed #130
  • Sep 03 17:25
    zakariaf commented #126
Gregory M Kohler
@gmkohler
Do you have a serializer defined for every class being serialized in the payload? For Namespace::ClassName, you need a Namespace::SerializableClassName
@karwank ^
Linus Sellberg
@yxhuvud
You can also define a lookup table with the class option. I couldn't find a way to define those lookup tables in the serializers themselves though, so it looks like it has to be in every use place.
Karol Karwacki
@karwank
what if I wanted to have two different serializers for two different versions of API ?
for the same resource
Matt Holtom
@mattholtom

Hello everyone, new to the community. I've done some research in the docs and various repos under jsonapi-rb organization, but I can't find an example of accepts_nested_attributes_for usage with a 'bulk' document. I think the JSONAPI spec may consider support for bulk updates/creates an extension, and it may have even been scrapped. I can see various PR's throughout the repos trying to implement this, but none which have been merged.

Has anyone else deserialized nested attributes from JSON-API format to a hash that rails can digest? Currently we have pretty standard rails controllers that accept form data from traditional ERB views/ form_for objects (cocoon actually) i.e.:

def update
    if parent.update_attributes(update_params)
      redirect_to next_url
    else
      render :edit
    end
  end

def update_params
    params.require(:parent).permit(:parent_attr_1, children_attributes: [:id, :description, :first_name,  :_destroy])
  end

And we seek to convert them to accepting JSON-API formatted json. Something like this:

# in controller
  deserializable_resource :children, class: DeserializableChild, only: [:update]

# in deserializer
class DeserializableChild < JSONAPI::Deserializable::Resource
  key_format(&:underscore)
  attributes
end

So my question is, is there a strategy I should follow? Has anyone done this in the past? Or is there another library that supports this out of the box? Our entire app is these nested forms, so it would be worth switching to AMS if they do support this officially. Thanks in advance for your insights!

Matthew Mongeau
@halogenandtoast
If attribute names are not camelcased, is there something I have setup incorrectly?
Matthew Mongeau
@halogenandtoast
Looks like I can do something like
class SerializableResource < JSONAPI::Serializable::Resource
  extend JSONAPI::Serializable::Resource::KeyFormat
  key_format -> (key) { key.to_s.camelize(:lower) }
end
nuheluxulu
@nuheluxulu
if one does a has_many, is it supposed to give the attributes of comments (assuming example)
Linus Sellberg
@yxhuvud
You need to specify that the association should be included when generating the response, too.
if you are running the controller integrations, that is probably done by adding include=comments to the request.
Psy-Q
@psy-q
is there something that helps me set up the relationships when i PATCH a resource to add/remove some related records?
oooh, there seems to be some magic going on, it seems to have parsed the related stuff into some kind of Ruby data structure
including guessing that "type": "database_users" would resolve to DatabaseUser and database_user_ids. so something is going on there
Psy-Q
@psy-q
just wonder what's the correct way to get at this data
it parses params to this:
=> <ActionController::Parameters {"_jsonapi"=><ActionController::Parameters {"data"=>{"relationships"=>{"database_users"=>{"data"=>[{"type"=>"database_users", "id"=>"1"}]}}, "type"=>"databases", "id"=>2}} permitted: false>, "format"=>:json, "controller"=>"databases", "action"=>"update", "id"=>"2", "database"=>{"type"=>"databases", "id"=>2, "database_user_ids"=>["1"], "database_user_types"=>["DatabaseUser"]}} permitted: false>
Psy-Q
@psy-q
which looks like the right kind of magic, so is it safe to get the IDs from params[:database][:database_user_ids]?
Psy-Q
@psy-q
i tried it with database.database_user_ids = params[:database][:database_user_ids] and it seems to work. so even if this isn't the "official" way, maybe it's useful
Linus Sellberg
@yxhuvud
Is it possible to make the api NOT emit {"meta"=>{"included"=>false}} for relationships that isn't included? It is very redundant and makes it more of a pain to generate documentation of how the responses to requests will look like.
Linus Sellberg
@yxhuvud
looks at the code used to generate it. No, it seems there are no option to not generate the bloat in question.
mathewbaltes
@mathewbaltes
Hi JSONApi-eers. Not sure if anyone is actually in this chat.
I was working with dynamoid and wanted to use the renderer out of the box. Enumerator::Lazy supports :to_a but does not implement :to_ary
Linus Sellberg
@yxhuvud
Because all objects respond to to_a, so using to_a would make the if statement pretty pointless.
pmokariya
@pmokariya
Is it possible to remove ID from the SerializableCLASSNAME ?
I need json response like below
{
"data": {
"type": "articles",
I don't want this ID here"id": "1",
"attributes": {
// ... this article's attributes
},
}
Francesco Belladonna
@Fire-Dragon-DoL
@pmokariya I doubt it, the id is required as part of the JSONAPI specs
is there some kind of caching support for rails? I see some parameters but struggling to identify how to use it
Alex Oliveira
@kurko
I've been away from the community for a while, but this month I'm going to pick a deserializer. People who are using jsonapi-rb, are you enjoying it? Any outstanding problems?
Psy-Q
@psy-q
it's working OK for me and after i found out that there is certain magic involved in deserializing relationships, it seems it does all i need. will upgrade my stack at some point and hope it still works then
Alex Oliveira
@kurko
Nice. Thanks @psy-q. The relationships part is trickiest I think, so good to know. Did you have to do any hacks/acrobatics to make it work?
bnpIng
@bnping
what is the diff between include and fields ?
include: [:author, comments: [:author]],
fields: { users: [:name, :email] },
Pavel Argentov
@argent-smith
Hi ppl. I've got an AR model named Instance and a serializer named SerializableInstance with some stuff in it. When I do render jsonapi: instance in my controller, it ignores the serializer: the output looks just like render json: instance. What could be wrong?
also, when I use class: { Instance: SerializableInstance } parameter, it doesn't render anything from the serializer, too
Pavel Argentov
@argent-smith
Found the reason: rendering was overridden in some legacy initializer code.
bnpIng
@bnping
how jsonapi_filter works ?
RobOldCodes
@RobOldCodes_twitter
Hi, I wasn't sure how actively the project is maintained so it's great to see people talking in here!
I'm just starting out on a new project- everything about the library looks great except that there are un-merged PRs that have been there a while
RobOldCodes
@RobOldCodes_twitter
Can people recommend this library for production use? Is it looking for new maintainers?
Amit Suryavanshi
@amitTheSongadya_twitter
I am trying to find specifications to create resources with ruby Duration type. Anyone has any recommendations ? Thanks.
Heinrich Klobuczek
@klobuczek
If there is nothing implemented so far I would use https://en.wikipedia.org/wiki/ISO_8601#Durations
Amit Suryavanshi
@amitTheSongadya_twitter
Okay, Thanks. That is how it stored in DB "P0M7DT0S"
Sylvain
@bsylvain
I am migrating from AMS. Is there a way to transform all attributes with dash to underscore?
1 reply
Thibault Clerc
@ThibaultClerc
Hello everyone ! I'm trying to get a URL response from an active_storage image I attached to a "UserDish" model, but I just can't find a way to achieve this with jsonapi: in my serializer. Has anyone got a clue ? Thank you.
1 reply
basically, I need to use a serializer for just a relationship inside another serializer
Nikola Buhinicek
@NBuhinicek_gitlab

Hey squad :wave:

I would like to create a, lets call it a, smart_attribute method that would have some sort of conditional check before adding those attributes to output. I thought that this would be pretty easy and would look smth like this

class BaseSerializer < JSONAPI::Serializable::Resource
  extend JSONAPI::Serializable::Resource::ConditionalFields

  class << self
    def smart_attribute(field, options = {}, &block)
      return unless field.in? smart_fields
      ...possibly more @object related logic...

      attribute(field, options) do
        block || @object.send(field)
      end
    end

But I dont have access to my @object in this place :|

I know that it can be done with conditional attributes right in the serializers, but my goal would be to have just attributes/smart_attributes in serializers and no conditions. Any ideas how to gain access to @object in this place?

Mijo Kaliger
@manikal

Hi everyone,

I'm struggling how to define attributes which are ActiveStorage (intro, photos).
The idea for those attributes is to return url(s).
If I define it like below, I get:

No serializable class defined for String
module Serializable
  class SerializableUser < JSONAPI::Serializable::Resource
    type 'users'

    attributes :name, :city, :age

    has_many :besties

    has_one :intro do
      data do
        Rails.application.routes.url_helpers.rails_blob_url(@object.intro, only_path: false) if @object.intro.attached?
      end
    end

    has_many :photos do
      data do
      end
    end
Mijo Kaliger
@manikal
Or should I just use :link?