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

fix(metadata): various parameter improvements #6867

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Dec 13, 2024

Q A
Branch? 3.4
  • Parameter::getValue() now takes a default value as argument getValue(mixed $default = new ParameterNotFound()): mixed
  • Parametes::get(string $key, string $parameterClass = QueryParameter::class) (but also has and remove) now has a default value as second argument to QueryParameter::class
  • Constraint violation had the wrong message when using property, fixed by using the key instead:
#[QueryParameter(property: 'id', key: 'int', constraints: [new Assert\Type('integer')], provider: [self::class, 'toInt']))]
-id: This value should be of type integer.
+int: This value should be of type integer.
See the `toInt` provider.
    public static function toInt(Parameter $parameter, array $parameters = [], array $context = []): ?Operation
    {
        if (null === ($operation = $context['operation'] ?? null)) {
            return null;
        }

        $value = $parameter->getValue();

        if (is_numeric($value)) {
            $value = (int) $value;
        }

        $parameters = $operation->getParameters();
        $parameters->add($parameter->getKey(), $parameter = $parameter->withExtraProperties(
            $parameter->getExtraProperties() + ['_api_values' => $value]
        ));

        return $operation->withParameters($parameters);
    }

Note that in the future I'd like to introduce "parameter transformers" to do some parameter value transformation. Stay tuned!

@soyuka soyuka merged commit 22cbd01 into api-platform:3.4 Dec 13, 2024
78 checks passed
soyuka added a commit that referenced this pull request Dec 13, 2024
* fix(jsonschema): hashmaps produces invalid openapi schema (#6830)

* fix(jsonschema): hashmaps produces invalid openapi schema

* fix

---------

Co-authored-by: soyuka <soyuka@users.noreply.github.com>

* fix: add missing error normalizer trait and remove deprecated interface (#6853)

* fix: test empty parameter against null (#6852)

fixes #6844

* Fix deprecation symfony/dependency-injection

* cs: run php-cs-fixer

* ci: use problem error normalizer trait

* fix(metadata): various parameter improvements (#6867)


- `Parameter::getValue()` now takes a default value as argument `getValue(mixed $default = new ParameterNotFound()): mixed`
- `Parametes::get(string $key, string $parameterClass = QueryParameter::class)` (but also `has` and `remove`) now has a default value as second argument to `QueryParameter::class`
- Constraint violation had the wrong message when using `property`, fixed by using the `key` instead:

---------

Co-authored-by: Vincent Amstoutz <vincent.amstoutz@les-tilleuls.coop>
Co-authored-by: mladencosa <39300405+mladencosa@users.noreply.github.com>
Co-authored-by: Michiel Kalle <michielkalle@users.noreply.github.com>
vinceAmstoutz pushed a commit to vinceAmstoutz/api-platform-core that referenced this pull request Dec 24, 2024
- `Parameter::getValue()` now takes a default value as argument `getValue(mixed $default = new ParameterNotFound()): mixed`
- `Parametes::get(string $key, string $parameterClass = QueryParameter::class)` (but also `has` and `remove`) now has a default value as second argument to `QueryParameter::class`
- Constraint violation had the wrong message when using `property`, fixed by using the `key` instead:
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