Skip to content
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

[cpp-pistache-server] Enumerations not generated #1317

Closed
brianwaters3 opened this issue Oct 25, 2018 · 2 comments · Fixed by #8886
Closed

[cpp-pistache-server] Enumerations not generated #1317

brianwaters3 opened this issue Oct 25, 2018 · 2 comments · Fixed by #8886

Comments

@brianwaters3
Copy link

Description

Currently the enumeration definition below generates a class with no members. The attached file archive.zip contains a complete definition (with several enumerations) that demonstrate this problem.

Archive.zip

openapi-generator version

v 3.3.0

OpenAPI declaration file content or url
    SupportedGADShapes:
      anyOf:
        - type: string
          enum:
            - POINT
            - POINT_UNCERTAINTY_CIRCLE
            - POINT_UNCERTAINTY_ELLIPSE
            - POLYGON
            - POINT_ALTITUDE
            - POINT_ALTITUDE_UNCERTAINTY
            - ELLIPSOID_ARC
        - type: string
Command line used for generation

java -jar /home/brian/code/git/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i updated/TS29122_MonitoringEvent.yaml -g cpp-pistache-server --config config -o ./code/MonitoringEvent/server/cpp-pistache-server

Steps to reproduce
  1. Create a blank working directory
  2. Unzip Archive.zip to the newly created directory.
  3. Generate the source using the provided command making path adjustments for your system.
  4. The class SupportedGADShapes in ./code/MonitoringEvent/server/cpp-pistache-server/model/SupportedGADShapes.h has no members.
Related issues/PRs
Suggest a fix/enhancement

The attached file SupportedGADShapes.zip contains the .h and .cpp definitions for the enumeration.
Note that an enumeration named "INVALID" has been added in the header and is used when no default is specified.

SupportedGADShapes.cpp-pistache-server.zip

...
    /////////////////////////////////////////////
    /// SupportedGADShapes members
    enum eSupportedGADShapes
    {
       INVALID,
       POINT,
       POINT_UNCERTAINTY_CIRCLE,
       POINT_UNCERTAINTY_ELLIPSE,
       POLYGON,
       POINT_ALTITUDE,
       POINT_ALTITUDE_UNCERTAINTY,
       ELLIPSOID_ARC
    };

    eSupportedGADShapes getValue() const;
    void setValue(eSupportedGADShapes const value);

protected:
    eSupportedGADShapes m_value;
...
...
nlohmann::json SupportedGADShapes::toJson() const
{
    nlohmann::json val;
    
    switch (m_value)
    {
       case eSupportedGADShapes::POINT:                        val = "POINT";  break;
       case eSupportedGADShapes::POINT_UNCERTAINTY_CIRCLE:     val = "POINT_UNCERTAINTY_CIRCLE";  break;
       case eSupportedGADShapes::POINT_UNCERTAINTY_ELLIPSE:    val = "POINT_UNCERTAINTY_ELLIPSE";  break;
       case eSupportedGADShapes::POLYGON:                      val = "POLYGON";  break;
       case eSupportedGADShapes::POINT_ALTITUDE:               val = "POINT_ALTITUDE";  break;
       case eSupportedGADShapes::POINT_ALTITUDE_UNCERTAINTY:   val = "POINT_ALTITUDE_UNCERTAINTY";  break;
       case eSupportedGADShapes::ELLIPSOID_ARC:                val = "ELLIPSOID_ARC";  break;
       default:                                                val = "INVALID";  break;
    }

    return val;
}

void SupportedGADShapes::fromJson(nlohmann::json& val)
{
    auto s = val.get<std::string>();
    
    m_value =
          (s == "POINT")                        ? eSupportedGADShapes::POINT :
          (s == "POINT_UNCERTAINTY_CIRCLE")     ? eSupportedGADShapes::POINT_UNCERTAINTY_CIRCLE :
          (s == "POINT_UNCERTAINTY_ELLIPSE")    ? eSupportedGADShapes::POINT_UNCERTAINTY_ELLIPSE :
          (s == "POLYGON")                      ? eSupportedGADShapes::POLYGON :
          (s == "POINT_ALTITUDE")               ? eSupportedGADShapes::POINT_ALTITUDE :
          (s == "POINT_ALTITUDE_UNCERTAINTY")   ? eSupportedGADShapes::POINT_ALTITUDE_UNCERTAINTY :
          (s == "ELLIPSOID_ARC")                ? eSupportedGADShapes::ELLIPSOID_ARC :
                eSupportedGADShapes::INVALID;
}

SupportedGADShapes::eSupportedGADShapes SupportedGADShapes::getValue() const
{
   return m_value;
}

void SupportedGADShapes::setValue(SupportedGADShapes::eSupportedGADShapes const value)
{
   m_value = value;
}
...
@federicovalenso
Copy link

Generator still generates enums the same way (a class with no members). Is there any chance that this issue will ever be fixed ?

@mfyuce
Copy link
Contributor

mfyuce commented Mar 3, 2021

Hi,
Thanks for the PR.

What is it that needed to fix and reopen and merge this PR? I will help if need.

Thanks a lot.

mfyuce pushed a commit to mfyuce/openapi-generator that referenced this issue Jun 16, 2021
…ing enum code generation;

* A class that has an `anyOf` specification, in cpp side will have no members: in stead it should have a member having the type `classname_anyOf`
* Thus, Its `==` operator is not present or wrongly filled
* An string enum, should have a better usage, hence the `setEnumValue`
* this PR, is a brigde between `stringenumclassname_anyOf` and `stringenumclassname`
* `anyOf` specification is not just about `Enums`, so a better handling is needed from mustache templates, hence new template model parameter `isStringEnumContainer`
wing328 pushed a commit that referenced this issue Jun 20, 2021
…e generation (#9786)

* Continuing from #1317 and its PRs for pistache server string enum code generation;
* A class that has an `anyOf` specification, in cpp side will have no members: in stead it should have a member having the type `classname_anyOf`
* Thus, Its `==` operator is not present or wrongly filled
* An string enum, should have a better usage, hence the `setEnumValue`
* this PR, is a brigde between `stringenumclassname_anyOf` and `stringenumclassname`
* `anyOf` specification is not just about `Enums`, so a better handling is needed from mustache templates, hence new template model parameter `isStringEnumContainer`

* PR fix: muttleyxd: `double semicolon`

* PR fix: wing328: `I think std::string is C++ only. What about adding x-is-string-enum-container instead in the postProcessModel operation in the C++ pistache server generator?`

* PR fix: wing328: `I think std::string is C++ only...` after fix get latest codes and then generate samples

Co-authored-by: Mehmet Fatih <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants