swagger-api / swagger-api/swagger-codegen

[PHP] Cannot use "parent" when current class scope has no parent

Open
#12,462 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When executing a request using PHP generated code I am getting the following error:
Cannot use "parent" when current class scope has no parent

This occurs (in my specific case) in the \Checkly\Client\Model\CheckList class with the listInvalidProperties method. The error is correct since the class does not extend another class since it is defined as following:
class CheckList implements ModelInterface, ArrayAccess

This is the generated method:

    public function listInvalidProperties()
    {
        $invalidProperties = parent::listInvalidProperties();

        return $invalidProperties;
    }

Full file can be found here:
CheckList.txt

Swagger-codegen version

I am using version 3

Swagger declaration file content or url

I use the following swagger file:
https://api.checklyhq.com/swagger.json

Command line used for generation

I use the following command to generate the code:

docker run --rm -v ".:/local/out" swaggerapi/swagger-codegen-cli-v3 generate \
    --invoker-package Checkly\\Client \
    -i https://api.checklyhq.com/swagger.json \
    -l php \
    -o /local/out/
Steps to reproduce

Generate the code, and execute a listing request.

Related issues/PRs
Suggest a fix/enhancement

Please note that I have no experience with mustache or this library, but i did notice the following which might be the cause:
In the modules/swagger-codegen/src/main/resources/php/model_generic.mustache file i noticed that everywhere the {{#parentSchema}} block was used except for in the listInvalidProperties method, there the {{#parent}} block is used instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-codegen/src/main/resources/php/model_generic.mustache and compare the parentSchema conditions used around listInvalidProperties with the other generated methods. Reproduce with the provided Docker command and Checkly Swagger document, then verify that the generated CheckList class no longer calls parent::listInvalidProperties() without a parent class.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.