[CPP] [RESTCPP] Bug resolving object/class names when referencing from the same file
Description
When defining an object which has a property of a type which was defined in the same file, the generator cannot solve the object/class name of that referenced type, resulting in '#/ObjectName' in the generated code instead of 'ObjectName'.
If, for example, an object 'Line' contains a property of type 'Point' ('Point' being defined in the same yaml file as 'Line'), the generated class 'Line' will have an attribute of type std::shared_ptr<#/Point>, and the include command '#include "#/Point.h"'.
This seems to be a problem when no path to the referenced type is given, i.e. the referencing is direct: $ref: '#/Point' If instead the path to the same file (e.g. geometries.yaml) is given $ref: './geometries.yaml#/Point' or an initial 'definitions' layer is added to the file $ref: '#/definitions/Point' the code is generated correctly.
Swagger-codegen version
swagger-generator-2.4.0
Swagger declaration file content or url
Failing (file geometries.yaml):
Point:
type: object
properties:
value:
type: integer
Line:
type: object
properties:
point:
$ref: './geometries.yaml#/Point'
#include "#/Point.h";
class Line : public ModelBase{
...
std::shared_ptr<#/Point> m_Point;
};
Working - 1 (file geometries.yaml)
Point:
type: object
properties:
value:
type: integer
Line:
type: object
properties:
point:
$ref: './geometries.yaml#/Point'
Working - 2 (file geometries.yaml)
definitions:
Point:
type: object
properties:
value:
type: integer
Line:
type: object
properties:
point:
$ref: '#/definitions/Point'
Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i ${YAML_SERVICE_FILE_INCLUDING_A_REFERENCE_TO_LINE}
-l cpprest
-c ${CONFIG_FILE}
-o ${OUTPUT_FOLDER}
Steps to reproduce
Simply create a service that includes a type 'Line' and generate the cpprest client
failing and working 1 are identical
Sorry, the referencing of the failing one is $ref: '#/Point':
Point:
type: object
properties:
value:
type: integer
Line:
type: object
properties:
point:
$ref: '#/Point'