gpt4 book ai didi

php - 在 API 平台注解中使用参数

转载 作者:行者123 更新时间:2023-12-04 03:45:45 25 4
gpt4 key购买 nike

我正在研究如何将动态变量添加到 API 平台 @ApiProperty 注释中。
我发现 Symfony 允许这样做,但它似乎不适用于 API 平台注释。
例如 :

/**
* Redirection URL.
*
* @Groups({"authorization_code_login_write", "authorization_code_logout_write"})
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "example"="%app.auth.default.redirect%"
* }
* }
* )
*/
protected ?string $redirectionUrl = null;
%app.auth.default.redirect% 不会被同名的容器参数替换。
我应该怎么做 ?

最佳答案

乍一看,我在这里只看到了一种方法 - 在 openapi_context 中创建自己的属性,比如说 my_redirect_example
像这样,例如:

"openapi_context"={
"type"="string",
"my_redirect_example"=true
}
然后你需要装饰 like in documentation
嗯,像这样:
public function normalize($object, $format = null, array $context = [])
{
$docs = $this->decorated->normalize($object, $format, $context);


$redirectUrl = .... # your own logic to get this dynamical value

foreach ($docs['paths'] as $pathName => $path) {
foreach ($path as $operationName => $operation) {
if ($operation['my_redirect_example'] ?? false) {
$docs['paths'][$pathName][$operationName]['example'] = $redirectUrl;
}
}
}

return $docs;
}
它应该工作。无论如何 - 这只是一个例子(我没有测试它),只是为了了解你如何处理它。
当然,你可以用你自己的值替换 true 值,并在 if 语句中使用它来根据你自己的一些逻辑来获取它。

关于php - 在 API 平台注解中使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65169759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com