Skip to content

fix(openapi): align /api/docs.yamlopenapi formatting with cli export#8263

Closed
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/openapi-yaml-format-8157
Closed

fix(openapi): align /api/docs.yamlopenapi formatting with cli export#8263
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/openapi-yaml-format-8157

Conversation

@soyuka

@soyuka soyuka commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

The HTTP /api/docs.yamlopenapi endpoint produced fully inlined single-line YAML while api:openapi:export --yaml produced a human-readable, indented document. The two paths normalized the OpenAPI object the same way but the encoder used at the HTTP boundary delegated to Symfony's default YamlEncoder (inline level 2, no extra flags) instead of using the same Yaml::dump(...) call as the CLI.

This PR makes ApiPlatform\Serializer\YamlEncoder::encode() call Yaml::dump($data, 10, 2, DUMP_OBJECT_AS_MAP | DUMP_EMPTY_ARRAY_AS_SEQUENCE | DUMP_MULTI_LINE_LITERAL_BLOCK | DUMP_NUMERIC_KEY_AS_STRING) directly, matching OpenApiCommand. The encoder is dedicated to the yamlopenapi format (see src/Symfony/Bundle/Resources/config/openapi/yaml.php), so no other format is affected.

Reproduction

GET /api/docs.yamlopenapi returns a single-line { openapi: 3.1.0, paths: { /foo: { get: ... } } } while bin/console api:openapi:export --yaml returns a multi-line indented document.

Test plan

  • Added testEncodeUsesOpenApiYamlFlags covering the new flag set (block style, tags: [], quoted numeric keys, literal multi-line scalars).
  • Updated the two existing assertions that pinned the old inline output.
  • vendor/bin/phpunit src/Serializer/Tests/YamlEncoderTest.php — 6/6 green.
  • vendor/bin/phpunit src/Serializer/Tests — 103/103 green.
  • vendor/bin/php-cs-fixer fix --dry-run on changed files — clean.
  • vendor/bin/phpstan analyse on changed files — clean.

Fixes #8157

@soyuka soyuka force-pushed the fix/openapi-yaml-format-8157 branch from 0ce3433 to 1e0c92d Compare June 9, 2026 14:19
The YamlEncoder used by the HTTP /api/docs.yamlopenapi endpoint delegated
to Symfony's default YamlEncoder, which dumps with inline=2 and no extra
flags, producing a single inlined line for the whole document. Meanwhile
api:openapi:export --yaml calls Yaml::dump with inline=10 and a richer
flag set (DUMP_OBJECT_AS_MAP | DUMP_EMPTY_ARRAY_AS_SEQUENCE |
DUMP_MULTI_LINE_LITERAL_BLOCK | DUMP_NUMERIC_KEY_AS_STRING).

Switch the YamlEncoder to call Yaml::dump directly with the same flags
so both surfaces yield the same human-readable output.

Fixes api-platform#8157
@soyuka soyuka force-pushed the fix/openapi-yaml-format-8157 branch from 1e0c92d to 1a14624 Compare June 9, 2026 14:21
@soyuka soyuka closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant