OpenAPITools / OpenAPITools/openapi-generator

[BUG] [PHP] array of objects class triggers Fatal Error

Open
#9,172 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Php generator makes fatal error for array of object
class ListOfMessage has no parent but it has this method with 'parent' call

class ListOfMessage implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public function listInvalidProperties()
    {
        $invalidProperties = parent::listInvalidProperties();

        return $invalidProperties;
    }
}

And fatal error happens
Deprecated: Cannot use "parent" when current class scope has no parent in
I have no acces to api and can't change it to

              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Message'

Also ObjectSerializer::deserialize doesn't unserialize such object properly: it empty

openapi-generator version

5.1 and latest from dockerhub

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Chat API
  version: "1.0.0-oas3"
  title: Chat API
  contact:
    email: spatialguru.net@gmail.com
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: admins
    description: Secured Admin-only calls
  - name: developers
    description: Operations available to regular developers
paths:
  '/api/v1/chat/{acctNum}/room/{id}/messages':
    get:
      tags:
        - developers
      summary: searches for messages by room
      operationId: messagesByRoomV1
      parameters:
        - in: path
          name: acctNum
          description: Account number of organization
          required: true
          schema:
            type: string
        - in: path
          name: id
          description: Chat room id
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: search results matching criteria
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListOfMessage'
        '400':
          description: bad input parameter
        '403':
          description: >-
            forbidden if account number does not match user organization account
            number and user is not a super-admin
        '500':
          description: internal server error
servers:
  - url: 'https://test.fake.io'
components:
  schemas:
    ListOfMessage:
      type: array
      items:
        $ref: '#/components/schemas/Message'
    Message:
      required:
        - id
        - createdOn
        - updatedOn
        - owner
        - ownerName
        - content
        - chatRoomId
      properties:
        id:
          type: integer
        createdOn:
          type: integer
        updatedOn:
          type: integer
        owner:
          type: integer
        ownerName:
          type: string
        content:
          type: string
        chatRoomId:
          type: integer`

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 by running the Makefile .generate target with the provided OpenAPI schema. Inspect the generated ListOfMessage class and ObjectSerializer::deserialize behavior for array-of-object models. Done means generation no longer emits a parent call for a class without a parent and deserialization produces the expected objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.