@@ -25,6 +25,8 @@ const assert = require('assert')
25
25
const semver = require ( 'semver' )
26
26
const helper = require ( './helper' )
27
27
const deepEqual = require ( 'fast-deep-equal' )
28
+ const { join } = require ( 'path' )
29
+ const { locations } = require ( '../../scripts/download-artifacts' )
28
30
const { ConfigurationError } = require ( '../../lib/errors' )
29
31
30
32
const { delve, to, isXPackTemplate, sleep } = helper
@@ -362,6 +364,11 @@ function build (opts = {}) {
362
364
if ( ! Array . isArray ( options . ignore ) ) options . ignore = [ options . ignore ]
363
365
if ( cmd . params . ignore ) delete cmd . params . ignore
364
366
367
+ // ndjson apis should always send the body as an array
368
+ if ( isNDJson ( cmd . api ) && ! Array . isArray ( cmd . params . body ) ) {
369
+ cmd . params . body = [ cmd . params . body ]
370
+ }
371
+
365
372
const [ err , result ] = await to ( api ( cmd . params , options ) )
366
373
let warnings = result ? result . warnings : null
367
374
const body = result ? result . body : null
@@ -696,6 +703,7 @@ function parseDo (action) {
696
703
// converts underscore to camelCase
697
704
// eg: put_mapping => putMapping
698
705
acc . method = val . replace ( / _ ( [ a - z ] ) / g, g => g [ 1 ] . toUpperCase ( ) )
706
+ acc . api = val
699
707
acc . params = camelify ( action [ val ] )
700
708
}
701
709
return acc
@@ -848,6 +856,12 @@ function shouldSkip (esVersion, action) {
848
856
return false
849
857
}
850
858
859
+ function isNDJson ( api ) {
860
+ const spec = require ( join ( locations . specFolder , `${ api } .json` ) )
861
+ const { content_type } = spec [ Object . keys ( spec ) [ 0 ] ] . headers
862
+ return Boolean ( content_type && content_type . includes ( 'application/x-ndjson' ) )
863
+ }
864
+
851
865
/**
852
866
* Updates the array syntax of keys and values
853
867
* eg: 'hits.hits.1.stuff' to 'hits.hits[1].stuff'
0 commit comments