Skip to content

[BUG][cpp-restsdk] Enums not generated #8937

@gluttony38

Description

@gluttony38

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

A member described with an enum has no corresponding enum when generating code for cpp-restsdk (and it seems to be the same for any C++ generators), it is then hard to map possible values from server to our code, and to ensure not setting an invalid value.

openapi-generator version

5.0.1

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/yaml/pet.yml

Pet status is described with an enum:

status: 
  type: string
  description: pet status in the store
  enum: 
    - available
    - pending
    - sold
Generation Details

Nothing special, but as you can see I use your sample that has the same issue.

Steps to reproduce

Simply generate the code for your sample, you can see in Java there is an enum generated
(see https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/Pet.java):

  public enum StatusEnum {
    AVAILABLE("available"),
    
    PENDING("pending"),
    
    SOLD("sold");

    private String value;

    StatusEnum(String value) {
      this.value = value;
    }
    [...]
  }
  [...]
  private StatusEnum status;

But in C++ a direct string is used making it hard to manage cleanly such member (see https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/cpp-restsdk/client/model/Pet.h):
utility::string_t m_Status

Related issues/PRs

Found issues for another generator but not for any C++ one.

Suggest a fix

Like in Java, instead of simply using a string, generate an enum and use it as type for such members.

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