Skip to content

[BUG] [php] [php-nextgen] Number as first character of Model #24732

Description

@jeroen1602

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When a schema name starts with a number and has an object property, then the class name for that object property starts with a number.
This is not allowed in PHP.

For the example below two model classes are created.

  • Model3dPosition
  • 3dPositionPosition

The first model gets the Model prefix to fix the name. The second one however doesn't get this prefix.

openapi-generator version
  • v7.24.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: modelWithANumber
  description: Example of a model generated with a number as first character
  version: 1.0.0
paths:
  /:
    get:
      operationId: first
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/3d-position'
          description: This route breaks
components:
  schemas:
    3d-position:
      type: object
      properties:
        position:
          type: object
          properties:
            x:
              type: integer
            y:
              type: integer
            z:
              type: integer
Generation Details

I used the following docker command:

docker run --rm --user "$UID:$(id -g)" \
    -v "$PWD":/local \
    openapitools/openapi-generator-cli:v7.24.0 generate \
    -i "/local/api.yml" \
    -g php-nextgen \
    -c /local/generate-nextgen.json \
    -o /local/nextgen/
Steps to reproduce
  • Generate the api as described above.
  • Check the model directory (src/Model)
  • See error for 3dPositionPosition.php.
  • Optionally lint using php -l
Related issues/PRs

I couldn't find anyting.

Suggest a fix

I think the logic that adds Model as a prefix should be expanded to also check the names for sub nested models.

This logic may also be missing for other generators

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions