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++][cpp-restsdk] Array of objects are not well handled. Compilation failed #922

Closed
CyrilleBenard opened this issue Aug 29, 2018 · 5 comments

Comments

@CyrilleBenard
Copy link

Description

The use of an array of objects generates wrong C++ code that do not compile. This is strange because I already tested this feature in the past with a previous generator version and it did not failed. It is almost a regression.

The compilation error looks like :

In file included from /home/cbenard/dev/amf/impl-ms1/src/client/client-ms2/gen-cpp/model/AmfUpdateEventSubscriptionItem.cpp:14:0:
/home/cbenard/dev/amf/impl-ms1/src/client/client-ms2/gen-cpp/model/AmfUpdateEventSubscriptionItem.h:37:18: error: expected template-name before ‘<’ token
     : public null<AmfUpdateEventSubscriptionItem_inner>
                  ^

NOTE: The object properties type does not interfere. I mean it also appears in case the properties are string or integer. See below

openapi-generator version

Current master 3.2.3-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check generation of array of object (cpp-restsdk)
  description: Internal ref filename is check_array_of_object.yaml 

servers:
  - url: http://localhost:8080

paths:
  /stair1:
    post:
      summary: blabla
      operationId: check_generation
      tags:
        - Stair1
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AmfUpdateEventSubscriptionItem'
        required: true
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                type: string
        default:
          description: Unexpected error

components:
  schemas:
    AmfUpdateEventSubscriptionItem:
      type: array
      items:
        type: object
        properties:
          prop1:
            type: string
          prop2:
            type: string
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Check generation of array of object (cpp-restsdk)",
    "description": "Internal ref filename is check_array_of_object.yaml"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/stair1": {
      "post": {
        "summary": "blabla",
        "operationId": "check_generation",
        "tags": [
          "Stair1"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AmfUpdateEventSubscriptionItem"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Expected response to a valid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "Unexpected error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AmfUpdateEventSubscriptionItem": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "prop1": {
              "type": "string"
            },
            "prop2": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
Command line used for generation

Generate :

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

Compile :

mkdir -p obj ; cd obj ; cmake -D CPPREST_ROOT=/usr/ ../gen-cpp ; make ; cd ..
Steps to reproduce

N/A

Related issues/PRs

N/A

Suggest a fix/enhancement
@CyrilleBenard
Copy link
Author

I also identify the "same" bug issue within an array of string, not only array of objects. I quoted "same" because the generated code is not done in the same way and the compilation error is not exactly the same.

@CyrilleBenard
Copy link
Author

Anyone may work on this bug issue ?
This kind of issue have heavy repercussions on the code generation because the generated model is wrong and so all its "users" or instantiations make a compilation failure... It seems that some related models are not generated in this case.
It's a chain reaction that makes the debugging and furthers evaluations really hard.
Any help would be really appreciated 😺

@etherealjoy
Copy link
Contributor

etherealjoy commented Oct 14, 2018

@CyrilleBenard
This one is difficult to solve. It is a problem for all generators with strict types like c++.

      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AmfUpdateEventSubscriptionItem'
        required: true
...
  schemas:
    AmfUpdateEventSubscriptionItem:
      type: array
      items:

Changing above spec to below is solvable though.

      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/AmfUpdateEventSubscriptionItem'
        required: true
...
  schemas:
    AmfUpdateEventSubscriptionItem:
    type: object
     properties:
          prop1:
            type: string
          prop2:
            type: string
      

@wing328
Can you suggest how this can be solved? or how other generators handle it .
I have the same problem with go and C# generators.

@etherealjoy
Copy link
Contributor

etherealjoy commented Nov 26, 2018

@CyrilleBenard
solved with #1296, Could you please verify

@CyrilleBenard
Copy link
Author

Agree @etherealjoy
Current master (3.3.4) solved this issue. 👍

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

3 participants