Skip to content

[REQ] Improve php-laravel generator output when using _oneOf_ #21095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
holkerveen opened this issue Apr 16, 2025 · 0 comments
Open

[REQ] Improve php-laravel generator output when using _oneOf_ #21095

holkerveen opened this issue Apr 16, 2025 · 0 comments

Comments

@holkerveen
Copy link

Is your feature request related to a problem? Please describe.

The generator output for a oneOf could be improved. I need properly typed models for each oneOf case. However, right now it seems to generate an object containing all possible properties.

Given this (minimal) example:

openapi: 3.0.0
info:
  title: Test oneOf
  version: 1
paths:
  /form-elements:
    get:
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  oneOf:
                    - $ref: '#/components/schemas/TextElement'
                    - $ref: '#/components/schemas/RadioElement'
components:
  schemas:
    TextElement:
      properties:
        type:
          type: string
          enum: [text]
        placeholder:
          type: string
    RadioElement:
      properties:
        type:
          type: string
          enum: [radio]
        options:
          type: array
          items:
            type: string

The php-laravel generator generates something like:

class FormElementsGet200ResponseInner {
    public function __construct(
        public \OpenAPI\Server\Model\RadioElementType $type,
        public string $placeholder,
        public array $options,
    ) {}

Where I would expect something more along the lines of e.g. the typescript-fetch generator:

export type FormElementsGet200ResponseInner = RadioElement | TextElement;
export function FormElementsGet200ResponseInnerFromJSON(json: any): FormElementsGet200ResponseInner {
    return FormElementsGet200ResponseInnerFromJSONTyped(json, false);
}
// .. other stuff

In addition I believe the \OpenAPI\Server\Model\RadioElementType in the constructor to be incorrect, as its type could also be TextElementType.

Describe the solution you'd like

I would like to extend support for at least oneOf in the php-laravel generator, so that the oneOf generates a proper set of models.

The generated code should be more usable that way. I would assume that fixing anyOf and allOf would be trivial once oneOf is working correctly.

Describe alternatives you've considered

I considered using the type as-is and creating the discriminator logic in my specific application, but I think it would be better to adapt the generator to be more precise.

Additional context

Requesting feedback here to check if the solution follows the general idea, before working on a PR. Would appreciate feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant