yii2-openapi
yii2-openapi copied to clipboard
Generator crash when using reference inside an object
components:
responses:
Contact:
description: 'Returns one contact by ID.'
content:
application/vnd.api+json:
schema:
type: object
properties:
data:
$ref: '#/components/schemas/Contact'
paths:
'/account/{accountId}/contacts':
parameters:
- name: accountId
in: path
description: ID of Account.
required: true
schema:
type: integer
get:
operationId: listAccountContacts
summary: List all Account's contacts
description: Returns all contacts for a account.
responses:
'200':
$ref: '#/components/responses/Contacts'
'403':
description: Response if the currently authenticated user has no access to this Account.
tags:
- Contacts
results in the following error:
$ ./yii gii/api
Running 'REST API Generator'...
PHP Notice 'yii\base\ErrorException' with message 'Undefined property: cebe\openapi\spec\Reference::$type'
in /app/vendor/cebe/yii2-openapi/src/lib/openapi/ResponseSchema.php:38
Stack trace:
#0 /app/vendor/cebe/yii2-openapi/src/lib/openapi/ResponseSchema.php(38): yii\base\ErrorHandler->handleError(8, 'Undefined prope...', '/app/vendor/ceb...', 38, Array)
#1 /app/vendor/cebe/yii2-openapi/src/lib/openapi/ResponseSchema.php(176): cebe\yii2openapi\lib\openapi\ResponseSchema::isArraySchemaWithRefItems(Object(cebe\openapi\spec\Reference))
#2 /app/vendor/cebe/yii2-openapi/src/lib/openapi/ResponseSchema.php(227): cebe\yii2openapi\lib\openapi\ResponseSchema::guessModelClassFromJsonResource(Object(cebe\openapi\spec\Reference))
#3 /app/vendor/cebe/yii2-openapi/src/lib/openapi/ResponseSchema.php(150): cebe\yii2openapi\lib\openapi\ResponseSchema::guessModelClassFromContent(Object(cebe\openapi\spec\MediaType))
#4 /app/vendor/cebe/yii2-openapi/src/lib/generators/RestActionGenerator.php(90): cebe\yii2openapi\lib\openapi\ResponseSchema::guessModelClass(Object(cebe\openapi\spec\Operation), 'create')
#5 /app/vendor/cebe/yii2-openapi/src/lib/generators/RestActionGenerator.php(74): cebe\yii2openapi\lib\generators\RestActionGenerator->prepareAction('post', Object(cebe\openapi\spec\Operation), Object(cebe\yii2openapi\lib\items\RouteData))
#6 /app/vendor/cebe/yii2-openapi/src/lib/generators/RestActionGenerator.php(56): cebe\yii2openapi\lib\generators\RestActionGenerator->resolvePath('/account/{accou...', Object(cebe\openapi\spec\PathItem))
#7 /app/vendor/cebe/yii2-openapi/src/generator/ApiGenerator.php(468): cebe\yii2openapi\lib\generators\RestActionGenerator->generate()
#8 /app/vendor/yiisoft/yii2-gii/src/console/GenerateAction.php(53): cebe\yii2openapi\generator\ApiGenerator->generate()
#9 /app/vendor/yiisoft/yii2-gii/src/console/GenerateAction.php(36): yii\gii\console\GenerateAction->generateCode()
#10 [internal function]: yii\gii\console\GenerateAction->run()
#11 /app/vendor/yiisoft/yii2/base/Action.php(93): call_user_func_array(Array, Array)
#12 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\Action->runWithParams(Array)
#13 /app/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('api', Array)
#14 /app/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction('api', Array)
#15 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('gii/api', Array)
#16 /app/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('gii/api', Array)
#17 /app/vendor/yiisoft/yii2/base/Application.php(384): yii\console\Application->handleRequest(Object(yii\console\Request))
#18 /app/yii(9): yii\base\Application->run()
#19 {main}
Note: This issue is reproduced only in PHP >= 8.0. https://github.com/SOHELAHMED7/yii2-openapi/actions/runs/8831887643/job/24248043503
Note: This issue is reproduced only in PHP >= 8.0. https://github.com/SOHELAHMED7/yii2-openapi/actions/runs/8831887643/job/24248043503
might depend on the error level:
https://www.php.net/manual/en/migration80.incompatible.php A number of notices have been converted into warnings:
- Attempting to read an undefined variable.
- Attempting to read an undefined property. [...]
@SOHELAHMED7 can you check/ensure that we are using error_reporting(-1) in tests?
can you check/ensure that we are using error_reporting(-1) in tests?
Done at https://github.com/cebe/yii2-openapi/pull/167