Skip to content

[C++][cpp-restsdk] Array of objects are not well handled. Compilation failed #922

@CyrilleBenard

Description

@CyrilleBenard
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

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