I'm sure I'm not the first to notice, and maybe I didn't search well enough, but couldn't find an existing issue regarding this.
Yaml::dump()
will produce arrays like this:
parameters:
-
name: username
in: path
description: 'name that need to be deleted'
required: true
type: string
-
in: body
name: body
description: 'Updated user object'
required: true
schema:
$ref: '#/definitions/User'
Instead of the more readable and preferred:
parameters:
- name: username
in: path
description: 'name that need to be deleted'
required: true
type: string
- in: body
name: body
description: 'Updated user object'
required: true
schema:
$ref: '#/definitions/User'
I first noticed this using "incenteev/composer-parameter-handler" (no mention of the issue there either), which will produce this:
# This file is auto-generated during the composer install
imports:
-
resource: parameters_base.yml
From a parameters.yml.dist which looks like this:
imports:
- { resource: parameters_base.yml }
Obviously the inlining is configurable in Yaml:dump
, the extra newline, as far as I can tell, is not.
Both are valid, so there is no bug.
Euhr.. Nobody said it was a bug, I said "more readable and preferred". Call it an "improvement".
Revisiting this after a few years鈥β燗 quick and dirty workaround is to preg_replace('/\-\n\s+/', '- ', Yaml::dump($array, 6))
. I used 6 as the inline level, adjust accordingly. Also, can't guarantee it won't mess with more complicated structures.
Most helpful comment
Euhr.. Nobody said it was a bug, I said "more readable and preferred". Call it an "improvement".