Skip to content

[BUG][php-nextgen] Discriminator values used for allowed enum values #23813

@coffeemakr

Description

@coffeemakr

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

If I have a schema, that has a oneOf discriminator and a type:

components:
  schemas:
    Pet:
      type: object
      properties:
        id:
          type: string
          minLength: 1
        animal:
          oneOf:
            - $ref: '#/components/schemas/Dog'
            - $ref: '#/components/schemas/Cat'
          discriminator:
            propertyName: type
            mapping:
              pet-dog: '#/components/schemas/Dog'
              pet-cat: '#/components/schemas/Cat'
    Dog:
      type: object
      properties:
        type:
          type: string
          enum: ["pet-dog"]
          default: "pet-dog"
        imageId:
          type: string
      required:
        - type
        - imageId
    Cat:
      type: object
      properties:
        type:
          type: string
          enum: ["pet-cat"]
          default: "pet-cat"
        imageId:
          type: string
        style:
          type: string
          enum:
            - "page"
            - "text"
            - "viewport"
      required:
        - type
        - imageId
        - style

The generated cobined class has a incorrect style allowed values in PetAnimal.php:

The following code is generated in

    public const TYPE_PET_CAT = 'pet-cat';
    public const TYPE_PET_DOG = 'pet-dog';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public static function getTypeAllowableValues()
    {
        return [
            self::TYPE_PET_CAT,
            self::TYPE_PET_DOG,
        ];
    }

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public static function getStyleAllowableValues()
    {
        return [
            self::TYPE_PET_CAT,
            self::TYPE_PET_DOG,
        ];
    }
openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce

I make a test: https://github.com/coffeemakr/openapi-generator/tree/issues-23813

Related issues/PRs
Suggest a fix

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