OpenAPITools / OpenAPITools/openapi-generator

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

Open
#24,732 3 comments 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?
  • 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

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

Run the provided Docker generation command with the sample OpenAPI declaration, then inspect src/Model/3dPositionPosition.php alongside Model3dPosition.php. Trace the php-nextgen model-name handling for nested object properties; done means the generated nested model has a valid PHP class name and passes php -l.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.