Skip to content

[BUG] Can't serialize objects when Enum are defined within an Object  #17999

@rvalim

Description

@rvalim

Bug Report Checklist

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

7.3.0

OpenAPI declaration file content or url
openapi: 3.0.3
components:
  schemas:
    TransportLocation:
      example:
        iataCode: ZRH
        locationType: AIRPORT
      properties:
        iataCode:
          description: IATA code for the location
          example: ZRH
          type: string
        locationType:
          description: Type of the transport location
          enum:
          - UNKNOWN
          - AIRPORT
          - TRAIN_STATION
          - BUS_STATION
          - AREA
          example: AIRPORT
          type: string
      required:
      - iataCode
      - locationType
      type: object
Generation Details

When generating code based on the provided yaml, there is no for the any enumeration property defined within an object.
Taking locationType as an example, I could solve it by first declaring an Enum object and then adding its reference to the TransportLocation, solution below:

    TransportLocationType:
      description: Type of the transport location
      enum:
        - UNKNOWN
        - AIRPORT
        - TRAIN_STATION
        - BUS_STATION
        - AREA
      type: string
      example: AIRPORT

    TransportLocation:
      example:
        iataCode: ZRH
        locationType: AIRPORT
      properties:
        iataCode:
          description: IATA code for the location
          example: ZRH
          type: string
        locationType:
          $ref: '#/components/schemas/TransportLocationType'
      required:
      - iataCode
      - locationType
      type: object

Only after that the properly EnumNameSerializer/Converted were created:

Scala version:
Screenshot 2024-02-29 at 08 07 23

Java version:
Screenshot 2024-02-29 at 07 58 26

Steps to reproduce

openapi-generator generate -c <yaml file path>

Related issues/PRs

Didn't found any one.

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