elasticsearch/docs/reference/docs
Nik Everett 6d2c40e546 Enforce that responses in docs are valid json (#26249)
All of the snippets in our docs marked with `// TESTRESPONSE` are
checked against the response from Elasticsearch but, due to the
way they are implemented they are actually parsed as YAML instead
of JSON. Luckilly, all valid JSON is valid YAML! Unfurtunately
that means that invalid JSON has snuck into the exmples!

This adds a step during the build to parse them as JSON and fail
the build if they don't parse.

But no! It isn't quite that simple. The displayed text of some of
these responses looks like:
```
{
    ...
    "aggregations": {
        "range": {
            "buckets": [
                {
                    "to": 1.4436576E12,
                    "to_as_string": "10-2015",
                    "doc_count": 7,
                    "key": "*-10-2015"
                },
                {
                    "from": 1.4436576E12,
                    "from_as_string": "10-2015",
                    "doc_count": 0,
                    "key": "10-2015-*"
                }
            ]
        }
    }
}
```

Note the `...` which isn't valid json but we like it anyway and want
it in the output. We use substitution rules to convert the `...`
into the response we expect. That yields a response that looks like:
```
{
    "took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,
    "aggregations": {
        "range": {
            "buckets": [
                {
                    "to": 1.4436576E12,
                    "to_as_string": "10-2015",
                    "doc_count": 7,
                    "key": "*-10-2015"
                },
                {
                    "from": 1.4436576E12,
                    "from_as_string": "10-2015",
                    "doc_count": 0,
                    "key": "10-2015-*"
                }
            ]
        }
    }
}
```

That is what the tests consume but it isn't valid JSON! Oh no! We don't
want to go update all the substitution rules because that'd be huge and,
ultimately, wouldn't buy much. So we quote the `$body.took` bits before
parsing the JSON.

Note the responses that we use for the `_cat` APIs are all converted into
regexes and there is no expectation that they are valid JSON.

Closes #26233
2017-08-17 09:02:10 -04:00
..
bulk.asciidoc Remove deprecated created and found from index, delete and bulk (#25516) 2017-07-07 13:58:46 -04:00
data-replication.asciidoc Add a high level description of ES's data replication model (#22327) 2017-01-10 13:17:48 +01:00
delete-by-query.asciidoc Further improve docs for requests_per_second 2017-08-15 15:57:07 -04:00
delete.asciidoc Remove deprecated created and found from index, delete and bulk (#25516) 2017-07-07 13:58:46 -04:00
get.asciidoc Remove usage of multi-types from the docs and added a page explaining type removal (#25543) 2017-07-05 12:30:19 +02:00
index_.asciidoc "result" : created -> "result" : "created" (#25446) 2017-08-15 14:53:05 -06:00
multi-get.asciidoc [Doc] Remove mention of generated fields in get/mget docs (#25492) 2017-07-04 18:06:00 +02:00
multi-termvectors.asciidoc CONSOLEify multi-termvectors docs 2017-02-08 11:47:42 +01:00
refresh.asciidoc Reword Refresh API reference (#19270) 2016-07-05 18:37:28 +02:00
reindex.asciidoc Further improve docs for requests_per_second 2017-08-15 15:57:07 -04:00
termvectors.asciidoc Docs: Fix termvectors by removing example blocks with embedded CONSOLE tests 2017-02-08 17:12:40 +01:00
update-by-query.asciidoc Further improve docs for requests_per_second 2017-08-15 15:57:07 -04:00
update.asciidoc Enforce that responses in docs are valid json (#26249) 2017-08-17 09:02:10 -04:00