Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Yaml] Add flag to dump numeric key as string #48127

Merged

Conversation

alamirault
Copy link
Contributor

@alamirault alamirault commented Nov 6, 2022

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #48061
License MIT
Doc PR TODO

Sometime Yaml keys must be always string. (OpenApi spec for example)

This PR add support to dump int as string by using the Yaml::DUMP_NUMERIC_KEY_AS_STRING flag.

Without flag (default)

200: foo

With flag

'200': foo

(Unrelated fabbot failure)

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@derrabus derrabus modified the milestones: 6.2, 6.3 Nov 7, 2022
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. At first glance, the implementation looks a bit too simple, but I might be mistaken. My main concern is the very poor test coverage for this new feature. Introducing a new flag adds complexity and possible side effects. We should especially make sure that the flag plays nicely when being combined with other flags that affect array structures or type casting of any sort.

src/Symfony/Component/Yaml/Tests/DumperTest.php Outdated Show resolved Hide resolved
nicolas-grekas added a commit that referenced this pull request Nov 9, 2022
…rault)

This PR was merged into the 6.2 branch.

Discussion
----------

[Yaml] Extract duplicate code to private function

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

I saw the same code/logic was duplicated in `Inline` class while working on #48127.
This little patch can avoid bug/inconsistency

Commits
-------

6026422 [Yaml] Extract duplicate code to private function
@alamirault alamirault force-pushed the feature/48061-yaml-dump-numeric-key-as-string branch 4 times, most recently from 377c613 to 27618ce Compare November 11, 2022 18:38
@alamirault alamirault requested review from derrabus and maxbeckers and removed request for xabbuh and derrabus November 11, 2022 18:44
@alamirault alamirault requested review from derrabus and removed request for maxbeckers November 11, 2022 18:44
src/Symfony/Component/Yaml/Dumper.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Inline.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/InlineTest.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/InlineTest.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/InlineTest.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/InlineTest.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/DumperTest.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/DumperTest.php Outdated Show resolved Hide resolved
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Antoine, thanks for this contribution

src/Symfony/Component/Yaml/CHANGELOG.md Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Tests/InlineTest.php Outdated Show resolved Hide resolved
@derrabus
Copy link
Member

Thank you @alamirault.

@derrabus derrabus closed this Dec 19, 2022
@derrabus derrabus force-pushed the feature/48061-yaml-dump-numeric-key-as-string branch from 47eafe9 to 35890e1 Compare December 19, 2022 08:23
@derrabus derrabus merged commit 52b5bb7 into symfony:6.3 Dec 19, 2022
@mabar
Copy link

mabar commented Dec 19, 2022

@alamirault Thank you for working on this!

@alamirault alamirault deleted the feature/48061-yaml-dump-numeric-key-as-string branch December 19, 2022 22:57
@fabpot fabpot mentioned this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yaml: dump numeric keys as strings instead of numbers
8 participants