JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Expose JSONAPI::ResourceSerializer#attribute_hash ?
Personne n'a encore pris cette issue.
- Langage dominant
- Ruby
- Étoiles
- 2.3k
- Forks
- 546
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Thanks for all the work on this gem. I've been using it for a new project and I really enjoy it.
For a project I'm currently working on, I have a Song model that has_one :embed. I don't want to expose the Embed model as part of the REST API. I always want to include the attributes of the embed in the response.
The JSON API format document explicitly states that says that attributes "may contain any valid JSON value" and that "complex data structures involving JSON objects and arrays are allowed as attribute values."
I propose that models specified as attributes in a resource should be serialized simply, using #attribute_hash.
For example, this is what my JSON looks like if I simply add :embed as an attribute to my SongResource
"embed": {
"id": 1,
"identifier": "1101",
"site": "youtube",
"art_content_id": 1,
"art_content_type": "Song",
"created_at": "2015-09-04T19:55:41.596Z",
"updated_at": "2015-09-04T19:55:41.596Z"
}
If it was passed through the serializer, this is what I would get. (this is what I want)
"embed": {
"identifier": "1101",
"site": "youtube"
}
Right now, I can do this by manually with code like this in my SongResource
def embed
resource = JSONAPI::Resource.resource_for @model.embed.class.to_s.underscore
serializer = JSONAPI::ResourceSerializer.new resource
serializer.send :attribute_hash, resource.new(@model.embed)
end
If you would be willing to consider a feature like this, I would be happy to put together a pull request for it
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par lire JSONAPI::ResourceSerializer et son point d’entrée privé attribute_hash, puis comparez la manière dont les attributs et les relations de SongResource sont actuellement sérialisés. Confirmez qu’un modèle intégré peut être sérialisé comme des attributs imbriqués, avec les champs identifier et site demandés, sans exposer Embed comme une ressource distincte.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- ruby
- Domaine
- api, backend
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100