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

Exclude Strategy with Until not working exepcted with .x #1312

Open
alexander-schranz opened this issue Apr 13, 2021 · 2 comments
Open

Exclude Strategy with Until not working exepcted with .x #1312

alexander-schranz opened this issue Apr 13, 2021 · 2 comments

Comments

@alexander-schranz
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps required to reproduce the problem

We are using the versioning of the jms serializer.

I first did have this:

<property name="sections" expose="true" since-version="3.0"/>
<virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="2.0" />
<virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="3.0" />

Then I did find out that the areas is still returned when using 3.0 version. So I did see in the docs: https://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies

There is something like 1.0.x used so I did use:

<property name="sections" expose="true" since-version="3.0"/>
<virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="1.x" />
<virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="2.x" />

but this didn't work the areas where not returned when requested with 2.0

Expected Result

**3.0**: Return `sections` without `areas`:
            "sections": [
                {
                    "_hash": "@string@",
                    "uuid": "@string@",
                    "name": "Section 1",
                    "areas": [
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "1"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "1A"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "2A"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "2B"
                        }
                    ]
                },
                {
                    "_hash": "@string@",
                    "uuid": "@string@",
                    "name": "Section 2",
                    "areas": [
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "1"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "1A"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "2A"
                        },
                        {
                            "_hash": "@string@",
                            "uuid": "@string@",
                            "name": "2B"
                        }
                    ]
                }
            ],
**2.0** Return `areas` without `sections`:
            "areas": [
                {
                    "section": "Section 1",
                    "areas": [
                        "1",
                        "1A",
                        "2A",
                        "2B"
                    ]
                },
                {
                    "section": "Section 2",
                    "areas": [
                        "1",
                        "1A",
                        "2A",
                        "2B"
                    ]
                }
            ],
**1.0** Return `areas` in old format without `sections`:
            "areas": [
                "1",
                "1A",
                "2A",
                "2B",
                "1",
                "1A",
                "2A",
                "2B"
            ],

Actual Result

See above.

Current workaround

Currently I did workaround by using .9999 as until version:

        <property name="sections" expose="true" since-version="3.0"/>

        <virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="1.9999" />
        <virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="2.9999" />
@goetas
Copy link
Collaborator

goetas commented Aug 6, 2021

The version exclusion strategy uses under the hood https://www.php.net/manual/en/function.version-compare.php

Whatever is supported by version_compare should work here.

It would be nice to move to https://github.com/composer/semver instead of version_compare

@W0rma
Copy link
Contributor

W0rma commented Oct 31, 2021

I don't think that the 1.0.x example from the docs have ever worked.

It would be nice to move to https://github.com/composer/semver instead of version_compare

I gave this a try in #1361 by adding a version-constraints attribute/VersionConstraints annotation which accept composer version constraints

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

No branches or pull requests

3 participants