Skip to content

Commit db6083a

Browse files
committed
Merge pull request #1602 from remear/docs-adapter-output-examples
Add output examples to Adapters docs
2 parents e1d1a3d + bfff46b commit db6083a

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Fixes:
3535
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
3636

3737
Misc:
38+
- [#1602](https://github.com/rails-api/active_model_serializers/pull/1602) Add output examples to Adapters docs (@remear)
3839
- [#1557](https://github.com/rails-api/active_model_serializers/pull/1557) Update docs regarding overriding the root key (@Jwan622)
3940
- [#1471](https://github.com/rails-api/active_model_serializers/pull/1471) [Cleanup] Serializer caching is its own concern. (@bf4)
4041
- [#1482](https://github.com/rails-api/active_model_serializers/pull/1482) Document JSON API implementation defs and progress in class. (@bf4)

docs/general/adapters.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ Use either the `JSON` or `JSON API` adapters if you want the response document t
4343
It's the default adapter, it generates a json response without a root key.
4444
Doesn't follow any specific convention.
4545

46+
##### Example output
47+
48+
```json
49+
{
50+
"title": "Title 1",
51+
"body": "Body 1",
52+
"publish_at": "2020-03-16T03:55:25.291Z",
53+
"author": {
54+
"first_name": "Bob",
55+
"last_name": "Jones"
56+
},
57+
"comments": [
58+
{
59+
"body": "cool"
60+
},
61+
{
62+
"body": "awesome"
63+
}
64+
]
65+
}
66+
```
67+
4668
### JSON
4769

4870
The response document always with a root key.
@@ -51,11 +73,72 @@ The root key **can't be overridden**, and will be derived from the resource bein
5173

5274
Doesn't follow any specific convention.
5375

76+
##### Example output
77+
78+
```json
79+
{
80+
"post": {
81+
"title": "Title 1",
82+
"body": "Body 1",
83+
"publish_at": "2020-03-16T03:55:25.291Z",
84+
"author": {
85+
"first_name": "Bob",
86+
"last_name": "Jones"
87+
},
88+
"comments": [{
89+
"body": "cool"
90+
}, {
91+
"body": "awesome"
92+
}]
93+
}
94+
}
95+
```
96+
5497
### JSON API
5598

5699
This adapter follows **version 1.0** of the [format specified](../jsonapi/schema.md) in
57100
[jsonapi.org/format](http://jsonapi.org/format).
58101

102+
##### Example output
103+
104+
```json
105+
{
106+
"data": {
107+
"id": "1337",
108+
"type": "posts",
109+
"attributes": {
110+
"title": "Title 1",
111+
"body": "Body 1",
112+
"publish-at": "2020-03-16T03:55:25.291Z"
113+
},
114+
"relationships": {
115+
"author": {
116+
"data": {
117+
"id": "1",
118+
"type": "authors"
119+
}
120+
},
121+
"comments": {
122+
"data": [{
123+
"id": "7",
124+
"type": "comments"
125+
}, {
126+
"id": "12",
127+
"type": "comments"
128+
}]
129+
}
130+
},
131+
"links": {
132+
"post-authors": "https://example.com/post_authors"
133+
},
134+
"meta": {
135+
"rating": 5,
136+
"favorite-count": 10
137+
}
138+
}
139+
}
140+
```
141+
59142
#### Included
60143

61144
It will include the associated resources in the `"included"` member

0 commit comments

Comments
 (0)