OpenAPITools / OpenAPITools/openapi-generator

[BUG] [php] [php-nexgen] allOf with annotation-only schema and string generates missing MixedString type

Open
#24,733 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

A schema I'm consuming uses a weird way to add a description to a property.

When a schema property uses allOf to combine an annotation-only schema with a primitive string schema, the PHP generators produce a property type named MixedString.

No MixedString class is generated, so the generated client can fail at runtime when deserializing that field.

The expected generated PHP type for the property should be string, or the generator should otherwise handle the annotation-only schema without producing an unresolved model/type name.

openapi-generator version
  • v7.24.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: anyOfTypeWithAnnotationOnlySchema
  description: Example of MixedString being generated with annotaiton only schema
  version: 1.0.0
paths:
  /:
    get:
      operationId: first
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/foo'
          description: This route breaks
components:
  schemas:
    foo:
      type: object
      properties:
        bar:
          allOf:
            - $ref: '#/components/schemas/note'
            - type: string
    note:
      description: This is just a note. That's all it is

Generation Details

I used the following commands for generation:

openapi-generator-cli generate
    -i ./api.yml
    -g php-nextgen
    -c ./generate-nextgen.json
    -o ./out
openapi-generator-cli generate
    -i ./api.yml
    -g php
    -c ./generate-old.json
    -o ./out
Steps to reproduce
  1. Generate using the steps above.
  2. Check the generated Foo model.
  3. See MixedString as type for the generated getter, setter, and openAPITypes for the field bar.
Related issues/PRs

I couldn't find anything.

Suggest a fix

I think empty schemas, as in this example should be filtered out for the type creation (the description should be combined?)
This should probably also be done for the anyOf path.

And maybe an allOf in combination with a primitive type should be disallowed. It's weird to have an allOf with a string and int.

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

Reproduce the issue with the provided OpenAPI YAML using both the php and php-nextgen generators, then inspect the generated Foo model and the generator paths handling allOf types. Done means the bar getter, setter, and openAPITypes use string without an unresolved MixedString type; consider the noted anyOf case as well.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, php
Domain
api, 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.