swagger-php
swagger-php copied to clipboard
Schema generation fails inside JsonContent
(Edit: This is now a feature request, not a failure - see comment chain)
Schema generation fails, when inside a JsonContent element.
Steps to reproduce:
With composer.json containing "zircote/swagger-php": "^4.10",
(4.10.6 in composer.lock)
With code
class myclass {
/**
* @OA\Info(
* title="API",
* version="1.1",
* description="API documentation",
* )
*
*/
/**
* @OA\Post(
* path="/path",
* @OA\Response(
* response="200",
* description="response",
* @OA\JsonContent(
* @OA\Schema(
* title="title",
* @OA\Property(
* property = "success",
* type = "boolean",
* example = true
* ),
* ),
* )
* )
* )
*
*/
protected function post(array $extraParams, array $queries) {
return;
}
}
Calling:
$oa = \OpenApi\Generator::scan(["src/"]);
echo $oa->toJson();
Results in output:
{
"openapi": "3.0.0",
"paths": {
"/path": {
"post": {
"operationId": "dd9f210a8294662e079e1c11b03617d8",
"responses": {
"200": {
"description": "response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
}
}
Notice that schema value is empty "{}"
Expected ouput::
{
"openapi": "3.0.0",
"paths": {
"/path": {
"post": {
"operationId": "dd9f210a8294662e079e1c11b03617d8",
"responses": {
"200": {
"description": "response",
"content": {
"application/json": {
"schema": {
"title": "title",
"properties": {
"success": {
"type": "boolean",
"example": true
}
},
"type": "object"
}
}
}
}
}
}
}
}}
Note that if inside the OA\JsonContent I enclose the schema inside a oneOf = {} and add a second dummy schema, I then see the correct schema output in the json.
Also note that the behaviour is the same if the schema is included as a reference, rather than inline.