Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Generator crash when using reference inside an object #163

Closed
siggi-k opened this issue Mar 8, 2024 · 3 comments · Fixed by SOHELAHMED7/yii2-openapi#31 or #166
Closed

Generator crash when using reference inside an object #163

siggi-k opened this issue Mar 8, 2024 · 3 comments · Fixed by SOHELAHMED7/yii2-openapi#31 or #166

Comments

@siggi-k
Copy link
Contributor

siggi-k commented Mar 8, 2024

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}

@SOHELAHMED7
Copy link
Contributor

Note: This issue is reproduced only in PHP >= 8.0. https://github.com/SOHELAHMED7/yii2-openapi/actions/runs/8831887643/job/24248043503

SOHELAHMED7 added a commit to SOHELAHMED7/yii2-openapi that referenced this issue Apr 25, 2024
SOHELAHMED7 added a commit to SOHELAHMED7/yii2-openapi that referenced this issue Apr 25, 2024
…g-reference-inside-an-object

Draft: Generator crash when using reference inside an object cebe#163
@cebe cebe closed this as completed in #166 Apr 29, 2024
@cebe
Copy link
Owner

cebe commented Apr 29, 2024

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?

@cebe cebe reopened this Apr 29, 2024
@SOHELAHMED7
Copy link
Contributor

can you check/ensure that we are using error_reporting(-1) in tests?

Done at #167

@cebe cebe closed this as completed May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants