gpt4 book ai didi

symfony - 如何通过 Swagger Decorator 在 API 平台中记录自定义 POST 操作?

转载 作者:行者123 更新时间:2023-12-05 07:10:42 25 4
gpt4 key购买 nike

In the docs there is this example , 但它只显示了如何添加一个 GET 操作。我想知道如何向文档添加自定义 POST 路由。

我无法显示示例正文请求,其中包含要发送的预期值(在此示例中为用户名和电子邮件)

我的尝试

<?php
// api/src/Swagger/SwaggerDecorator.php

namespace App\Swagger;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final class SwaggerDecorator implements NormalizerInterface
{
private $decorated;

public function __construct(NormalizerInterface $decorated)
{
$this->decorated = $decorated;
}

public function normalize($object, $format = null, array $context = [])
{
$docs = $this->decorated->normalize($object, $format, $context);


$customDefinition = [
'tags' => [
'default'
],
'name' => 'fields',
'description' => 'Testing decorator',
'default' => 'id',
'in' => 'query',
'requestBody' =>
[
'content' => [
'application/json' => [
'schema' => [
'description' => 'abcd',
'required' => [
'username', 'email'
],
'properties' => [
'username', 'email'
],
]
]
],
'description' => 'testing'
],
];

$docs['paths']['/testing']['post']['parameters'][] = $customDefinition;

return $docs;
}

public function supportsNormalization($data, $format = null)
{
return $this->decorated->supportsNormalization($data, $format);
}
}

但它不起作用。 enter image description here

最佳答案

你不应该将整个路由声明放在参数数组中,你应该这样创建:

$docs['paths']['/testing']['post'] = $customDefinition;

关于symfony - 如何通过 Swagger Decorator 在 API 平台中记录自定义 POST 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61110339/

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