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

[C++][Pistache-server] "anyOf" keyword generates code that do not compile #537

Open
CyrilleBenard opened this issue Jul 11, 2018 · 2 comments

Comments

@CyrilleBenard
Copy link

Description

As far as I know, the generator is not yet compliant with the anyOf syntax but I'm not sure of that because the generator does not fail nor warn when it encounter it (?).

On the other hand, the generator produces a C++ code that do not compile, using Object type that has not been defined or mapped ?

One of compile error looks like :

In file included from ./model/Content.h:24:0,
                 from api/CheckApi.h:29,
                 from api/CheckApi.cpp:13:
./model/AmfEventArea.h:24:20: fatal error: Object.h: No such file or directory

See also AmfEventArea.h for Object type usage

class  AmfEventArea
    : public ModelBase
{
public:
    AmfEventArea();
    virtual ~AmfEventArea();

    /////////////////////////////////////////////
    /// ModelBase overrides

    void validate() override;

    nlohmann::json toJson() const override;
    void fromJson(nlohmann::json& json) override;

    /////////////////////////////////////////////
    /// AmfEventArea members

    /// <summary>
    /// 
    /// </summary>
    Object getPresence() const;
    void setPresence(Object const& value);
    bool presenceIsSet() const;
    void unsetPresence();

protected:
    Object m_Presence;
    bool m_PresenceIsSet;
};

Below a sample to easily reproduce the error

openapi-generator version

3.1.1-SNAPSHOT

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check ByteArray
servers:
  - url: http://localhost:8080
paths:
  /CheckAnyOf:
    get:
      summary: Check AnyOf generation
      operationId: list
      tags:
        - Check
      responses:
        '200':
          description: Everythings gonna be alright
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Content"
      default:
        description: unexpected error
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Content"

components:
  schemas:
    PresenceState:
      anyOf:
      - type: string
        enum:
          - "IN"
          - "OUT"
          - "UNKNOWN"
      - type: string

    AmfEventArea:
      type: object
      properties:
        presence:
          $ref: '#/components/schemas/PresenceState'

    Content:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/AmfEventArea'
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Check ByteArray"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/CheckAnyOf": {
      "get": {
        "summary": "Check AnyOf generation",
        "operationId": "list",
        "tags": [
          "Check"
        ],
        "responses": {
          "200": {
            "description": "Everythings gonna be alright",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Content"
                }
              }
            }
          }
        },
        "default": {
          "description": "unexpected error",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Content"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PresenceState": {
        "type": "string\nenum:\n  - \"IN\"\n  - \"OUT\"\n  - \"UNKNOWN\""
      },
      "AmfEventArea": {
        "type": "object",
        "properties": {
          "presence": {
            "$ref": "#/components/schemas/PresenceState"
          }
        }
      },
      "Content": {
        "type": "object",
        "properties": {
          "type": {
            "$ref": "#/components/schemas/AmfEventArea"
          }
        }
      }
    }
  }
}
Command line used for generation

Generation

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -c ./config.json -o .

Compilation

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/CheckApi.o api/CheckApi.cpp
Steps to reproduce

Just generate and compile

Related issues/PRs

N/A

Suggest a fix/enhancement
@CyrilleBenard
Copy link
Author

Fixed at least with current master 3.3.2-SNAPSHOT but I did not notice the exact version that has fixed this issue.
The anyOf is still not well handled but the generated code compile.

@wing328
Copy link
Member

wing328 commented Dec 10, 2018

#1360 has been merged into master so the anyOf mustache tag is available and the templates can leverage this to support anyOf in the code.

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

2 participants