-
-
Notifications
You must be signed in to change notification settings - Fork 880
Open
Labels
Description
Version
5.5.0
Description
Demo
Attached with this issue there is a screen recording of the issue; it's a little hard to explain in words but very easy to understand when observed.
Steps to reproduce:
- Make a DTO with an integer property (OA\Property (
#[OA\Property(type: 'integer')]) - Make a POST/PUT route with a RequestBody where the
contentcontains (at least) two MediaType objects: one should be of typeapplication/x-www-form-urlencodedand the otherapplication/json. Both should use the DTO defined in 1. - Go to /api/doc and find the call you defined.
- Click on "Try out" making sure that
application/x-www-form-urlencodedis selected in the dropdown - Switch the dropdown to 'application/json`
Expected result:
- The content is changed to a JSON with the integer field containing
0. For example:{ "myIntegerVar": 0 }.
Result:
- The content is changed to a JSON where each key is an object of the form
{ "myIntegerVar": { "value": "0", "errors": [] } }.
Code example
With a fresh symfony and nelmio/api-doc-bundle installation, the following code shows the error.
If anyone would find it useful, I can provide the full project.
Controller
<?php
// src/Controller/DummyController.php
namespace App\Controller;
use App\Model\DummyRequestModel;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Nelmio\ApiDocBundle\Attribute\Model;
use OpenApi\Attributes as OA;
use OpenApi\Attributes\RequestBody;
use OpenApi\Attributes\Schema;
use Symfony\Component\Routing\Annotation\Route;
class DummyController extends AbstractController
{
#[Route('/api/dummy', methods: ['POST'])]
#[RequestBody(content: [
new OA\MediaType(
mediaType: 'application/x-www-form-urlencoded',
schema: new Schema(ref: new Model(type: DummyRequestModel::class))
),
new OA\MediaType(
mediaType: 'application/json',
schema: new Schema(ref: new Model(type: DummyRequestModel::class))
),
])]
public function dummyAction()
{
return $this->json(new DummyRequestModel());
}
}
DTO
<?php
// src/Model/DummyRequestModel.php
namespace App\Model;
use OpenApi\Attributes as OA;
class DummyRequestModel
{
#[OA\Property(type: 'integer')]
public int $foo;
}
Thanks in advance for all the thoughts and help :)
JSON OpenApi
JSON OpenApi
{
"openapi": "3.0.0",
"info": {
"title": "My App",
"description": "This is an awesome app!",
"version": "1.0.0"
},
"paths": {
"/api/dummy": {
"post": {
"operationId": "post_app_dummy_dummy",
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/DummyRequestModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/DummyRequestModel"
}
}
}
},
"responses": {
"default": {
"description": ""
}
}
}
}
},
"components": {
"schemas": {
"DummyRequestModel": {
"required": [
"foo"
],
"properties": {
"foo": {
"title": "Get the value of foo",
"type": "integer"
}
},
"type": "object"
}
}
}
}
Additional context
No response