You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**id** (optional): The key to use as the reference. Default = 'id'.
29
29
-**blacklist** (optional): An array of blacklisted attributes. Default = [].
30
30
-**whitelist** (optional): An array of whitelisted attributes. Default = [].
31
-
-**links** (optional): An *object* or a *function* that describes the links inside data. (If it is an object values can be string or function).
32
-
-**topLevelMeta** (optional): An *object* or a *function* that describes the top-level meta. (If it is an object values can be string or function).
33
-
-**topLevelLinks** (optional): An *object* or a *function* that describes the top-level links. (If it is an object values can be string or function).
31
+
-**links** (optional): Describes the links inside data. It can be:
32
+
- An *object* (values can be string or function).
33
+
- A *function* with one argument `function(data) { ... }` or with two arguments `function(data, extraData) { ... }`
34
+
-**topLevelMeta** (optional): Describes the top-level meta. It can be:
35
+
- An *object* (values can be string or function).
36
+
- A *function* with one argument `function(extraData) { ... }` or with two arguments `function(data, extraData) { ... }`
37
+
-**topLevelLinks** (optional): Describes the top-level links. It can be:
38
+
- An *object* (values can be string or function).
39
+
- A *function* with one argument `function(extraData) { ... }` or with two arguments `function(data, extraData) { ... }`
34
40
-**relationships** (optional): An object defining some relationships
35
41
- relationship: The property in data to use as a relationship
36
42
- **type**: The type to use for serializing the relationship (type need to be register)
37
43
- **alternativeKey** (optional): An alternative key to use if relationship key not exist (example: 'author_id' as an alternative key for 'author' relationship). See [issue #12](https://github.com/danivek/json-api-serializer/issues/12).
38
44
- **schema** (optional): A custom schema for serializing the relationship. If no schema define, it use the default one.
39
-
- **links** (optional): An *object* or a *function* that describes the links for the relationship. (If it is an object values can be string or function).
45
+
- **links** (optional): Describes the links for the relationship. It can be:
46
+
- An *object* (values can be string or function).
47
+
- A *function* with one argument `function(data) { ... }` or with two arguments `function(data, extraData) { ... }`
40
48
-**convertCase** (optional): Case conversion for serializing data. Value can be : `kebab-case`, `snake_case`, `camelCase`
41
49
42
50
**Deserialization options:**
@@ -53,7 +61,7 @@ To avoid repeating the same options for each type, it's possible to add global o
53
61
var JSONAPISerializer =require('json-api-serializer');
Serialize it with the corresponding resource type, data and optional extra options :
180
+
Serialize it with the corresponding resource type, data and optional extra data :
173
181
174
182
```javascript
175
183
// Synchronously (blocking)
@@ -189,7 +197,8 @@ The output data will be :
189
197
"version": "1.0"
190
198
},
191
199
"meta": {
192
-
"count": 2
200
+
"count": 2,
201
+
"total": 1
193
202
},
194
203
"links": {
195
204
"self": "/articles"
@@ -360,8 +369,8 @@ Example :
360
369
```javascript
361
370
relationships: {
362
371
comments: {
363
-
type:'comment'
364
-
schema:'customSchema'
372
+
type:'comment'
373
+
schema:'customSchema'
365
374
}
366
375
}
367
376
```
@@ -371,8 +380,12 @@ relationships: {
371
380
If your data contains one or multiple objects of varying types, it's possible to define a configuration object instead of the type-string as the first argument of ```serialize``` and ```serializeAsync``` with these options:
372
381
373
382
-**type** (required): A *string* for the path to the key to use to determine type or a *function* deriving a type-string from each data-item.
374
-
-**topLevelMeta** (optional): An *object* or a *function* that describes the top-level meta. (If it is an object values can be string or function).
375
-
-**topLevelLinks** (optional): An *object* or a *function* that describes the top-level links. (If it is an object values can be string or function).
383
+
-**topLevelMeta** (optional): Describes the top-level meta. It can be:
384
+
- An *object* (values can be string or function).
385
+
- A *function* with one argument `function(extraData) { ... }` or with two arguments `function(data, extraData) { ... }`
386
+
-**topLevelLinks** (optional): Describes the top-level links. It can be:
387
+
- An *object* (values can be string or function).
388
+
- A *function* with one argument `function(extraData) { ... }` or with two arguments `function(data, extraData) { ... }`
0 commit comments