Skip to content

Commit b92b9e1

Browse files
authored
Changed json blocks to use yaml tag (#2477)
1 parent b5d8a44 commit b92b9e1

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

api-design-guidelines/data-modelling.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ JSON objects must be conceptually treated as **unordered**. Maintaining order of
88

99
If preservation of order is important, such ordering information should be represented separately. The examples below shows a plain (unordered) object alongside three alternative representations which also provide ordering detail.
1010

11-
```json
11+
```yaml
1212
// Plain object (unordered)
1313
{
1414
"one": "eins",
@@ -49,15 +49,15 @@ JSON objects and query string parameters must not use duplicate keys. The behavi
4949
Nulls are sometimes used to mark a value as "missing" or "not available". Instead of returning `null` as a value in JSON prefer to omit the field in the response. Empty strings (`""`) should similarly not be used to denote a missing string value as they can be confused for an explicit value of the empty string. It is fine to accept `null` in the request if they have special semantics such as unsetting a value. Otherwise fields that would have null or empty string values should also be omitted in the request.
5050

5151
- DON'T:
52-
```json
52+
```yaml
5353
{"key1": 1, "key2": null}
5454
```
5555
- DON'T:
56-
```json
56+
```yaml
5757
{"key1": 1, "key2": ""}
5858
```
5959
- DO:
60-
```json
60+
```yaml
6161
{"key1": 1}
6262
```
6363

@@ -107,35 +107,35 @@ Modelling objects that are a mix between static and dynamic keys is more complex
107107

108108
An example of mixed static and dynamic keys can be seen in the `indices.field_usage_stats` endpoint response:
109109

110-
```json
110+
```yaml
111111
{
112112
"_shards": {
113113
"total": 1,
114114
"successful": 1,
115115
"failed": 0
116116
},
117-
"my-index": { ... }
117+
"my-index": {...}
118118
}
119119
```
120120

121121
The key `"my-index"` is user-defined wheras `"_shards"` is static. This API would be easier to model by keeping all dynamic keys in their own object:
122122

123-
```json
123+
```yaml
124124
{
125125
"_shards": {
126126
"total": 1,
127127
"successful": 1,
128128
"failed": 0
129129
},
130130
"indices": {
131-
"my-index": { ... }
131+
"my-index": {...}
132132
}
133133
}
134134
```
135135

136136
Or better yet, to completely avoid using dynamic keys the user-defined value can be a property value within the object itself:
137137

138-
```json
138+
```yaml
139139
{
140140
"_shards": {
141141
"total": 1,
@@ -152,7 +152,7 @@ Or better yet, to completely avoid using dynamic keys the user-defined value can
152152

153153
Sometimes an API accepts an object but the keys are determined by what "kind/variant" of the object is intended. An example of this is aggregations, queries, and pipeline steps. There are two ways the Elasticsearch API handles this situation. The first method is using an **internal variant type** property like "type" with analyzers:
154154

155-
```json
155+
```yaml
156156
{
157157
"type": "snowball",
158158
"stopwords": ["if", "and", "but"]
@@ -161,7 +161,7 @@ Sometimes an API accepts an object but the keys are determined by what "kind/var
161161

162162
The second is using **external variants** where the inner object is wrapped with an object with a single key containing the kind of the inner object. This example changes the analyzer from above to use an external variant:
163163

164-
```json
164+
```yaml
165165
{
166166
"snowball": {
167167
"stopwords": ["if", "and", "but"]
@@ -254,7 +254,7 @@ Many of our APIs support users supplying values in multiple different formats. F
254254

255255
For the sake of user experience we should accept values in different formats. For values that accept multiple formats the format should be explicitly set by users so Elasticsearch can interpret and validate the value based on the given format. For example:
256256

257-
```json
257+
```yaml
258258
{"type": "date", "format": "yyyy-MM-dd HH:mm:ss"}
259259
```
260260

api-design-guidelines/naming.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Some programming languages place special meaning on underscore prefixes and suff
5454

5555
See the below example with a JSON object with two properties `nodes` and `_nodes`:
5656

57-
```json
57+
```yaml
5858
{
5959
"nodes": {...},
6060
"_nodes": {...}
@@ -63,7 +63,7 @@ See the below example with a JSON object with two properties `nodes` and `_nodes
6363

6464
For this API the generated structure in some programming languages would have a clash between the names of the two properties which would require inventing a name for one of the properties. Diversions from the API as it is on the wire are likely to cause confusion for users and should be avoided if possible. Instead these properties could be named more semantically as follows:
6565

66-
```json
66+
```yaml
6767
{
6868
"nodes": {...},
6969
"node_info": {...}

api-design-guidelines/requests-responses.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This principle allows for simpler consumer code that neither has to remember sta
111111

112112
An example of this is the datafeeds API which accepts either a string or list of strings for indices but always returns a list of strings:
113113

114-
```json
114+
```yaml
115115
PUT /_ml/datafeeds/feed-id
116116
{
117117
"indices": "index-name", // Input is a string.
@@ -139,7 +139,7 @@ The `name` of the function is typically restricted to alphanumeric characters an
139139

140140
Functions also only allow a single return / response type which is the "nominal successful response". Error responses can vary based on status code but at a minimum should match the following structure:
141141

142-
```json
142+
```yaml
143143
{
144144
"type": "error type",
145145
"reason": "<human readable message>",

0 commit comments

Comments
 (0)