Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #537
Closed
Open
Issue created Jul 11, 2018 by Administrator@rootContributor

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

Created by: CyrilleBenard

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
Assignee
Assign to
Time tracking