OpenAPITools / OpenAPITools/openapi-generator
[BUG][cpp-restsdk] key-type of a map is hardcoded to utility::string_t
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The cpp-restsdk generator always uses utility::string_t as the type of the key in an std::map, even if a different type-mapping is given.
openapi-generator version
v7.20.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Example
description: Example
version: 1.0.0
components:
schemas:
Pet:
type: object
properties:
name:
type: string
age:
type: integer
required: [ name, age ]
PetCollection:
type: object
properties:
collectionName:
type: string
owners:
type: array
items:
type: string
pets:
type: object
additionalProperties:
$ref: "#/components/schemas/Pet"
required: [collectionName, owners, pets]
Generation Details
java -jar openapi-generator-cli-7.20.0.jar generate -i openapi.yaml -g cpp-restsdk -o petstore --type-mappings string=std::string
Steps to reproduce
- Generate C++ code as described above
- Check type of
m_PetsinPetCollection.h
The current result is
std::map<utility::string_t, std::shared_ptr<Pet>> m_Pets;
while the expected outcome is
std::map<std::string, std::shared_ptr<Pet>> m_Pets;
Note that the type-mapping for m_CollectionName and m_Owners is correct and uses the provided std::string.
Related issues/PRs
-
Suggest a fix
It looks like utility::string_t is hardcoded in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java#L466
Probably utility::string_t on this line has to be changed to getSchemaType("string")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java around line 466, then run the provided Java generation command with the sample OpenAPI YAML. Check PetCollection.h and confirm the map key follows the supplied string type mapping while the existing property mappings remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100