fix(openapi): align /api/docs.yamlopenapi formatting with cli export#8263
Closed
soyuka wants to merge 1 commit into
Closed
fix(openapi): align /api/docs.yamlopenapi formatting with cli export#8263soyuka wants to merge 1 commit into
soyuka wants to merge 1 commit into
Conversation
0ce3433 to
1e0c92d
Compare
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
1e0c92d to
1a14624
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The HTTP
/api/docs.yamlopenapiendpoint produced fully inlined single-line YAML whileapi:openapi:export --yamlproduced 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 defaultYamlEncoder(inline level 2, no extra flags) instead of using the sameYaml::dump(...)call as the CLI.This PR makes
ApiPlatform\Serializer\YamlEncoder::encode()callYaml::dump($data, 10, 2, DUMP_OBJECT_AS_MAP | DUMP_EMPTY_ARRAY_AS_SEQUENCE | DUMP_MULTI_LINE_LITERAL_BLOCK | DUMP_NUMERIC_KEY_AS_STRING)directly, matchingOpenApiCommand. The encoder is dedicated to theyamlopenapiformat (seesrc/Symfony/Bundle/Resources/config/openapi/yaml.php), so no other format is affected.Reproduction
GET /api/docs.yamlopenapireturns a single-line{ openapi: 3.1.0, paths: { /foo: { get: ... } } }whilebin/console api:openapi:export --yamlreturns a multi-line indented document.Test plan
testEncodeUsesOpenApiYamlFlagscovering the new flag set (block style,tags: [], quoted numeric keys, literal multi-line scalars).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-runon changed files — clean.vendor/bin/phpstan analyseon changed files — clean.Fixes #8157