JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Meta key_format setting
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Right now (in 0.8.0-beta2) we can use the configuration option of json_key_format to change the style of the attribute key names (dasherized, camelized, etc) but there is no way to do so for meta data!
I am suggesting we add a similar configuration option for formatting the key names of meta data. Something along the lines of json_meta_key_format.
Here is an example:
# using: config.json_key_format = :camelized_key
class UserResource < JSONAPI::Resource
attributes :first_name, :last_name
def meta(_options = {})
{
formal_name: "#{@model.last_name}, #{@model.first_name}"
}
end
end
Will return something like this currently:
"data": {
"attributes": {
"firstName": "foo",
"lastName": "bar"
},
"meta": {
"formal_name": "bar, foo"
},
...
}
What I propose is a json_meta_key_format configuration, which, for example sake would return with the following when using config.json_meta_key_format = :camelized_key:
"data": {
"attributes": {
"firstName": "foo",
"lastName": "bar"
},
"meta": {
"formalName": "bar, foo"
},
...
}
(Notice formalName instead of formal_name)
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der vorhandenen json_key_format-Konfiguration und der im Issue gezeigten Resource-Meta-Methode und verfolgen Sie anschließend, wo Metadatenschlüssel serialisiert werden. Fügen Sie das vorgeschlagene Verhalten von json_meta_key_format hinzu, damit formal_name zu formalName werden kann, und überprüfen Sie, dass das generierte JSON dem Beispiel entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- api
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100