Bug Report Checklist
Description
The cpp-httplib-server generator incorrectly generates or references model headers for OpenAPI primitive/built-in types.
In particular, responses using primitive string or binary/file schemas can result in generated code containing invalid model includes such as:
#include "model/String.h"
or:
These models are not defined in the OpenAPI specification and should not be generated.
For example, a response defined as:
content:
text/plain:
schema:
type: string
should be mapped to the corresponding C++ primitive type, such as std::string, rather than a generated String model.
Similarly, a binary response such as:
content:
application/octet-stream:
schema:
type: string
format: binary
should be mapped to the generator's appropriate binary/file representation rather than resulting in a reference to a non-existent model/File.h.
This makes the generated server code fail to compile because the referenced model headers do not exist.
openapi-generator version
OpenAPI Generator: 7.25.0
Generator:
OpenAPI version:
OpenAPI declaration file content or url
Minimal reproducible specification:
openapi: 3.1.0
info:
title: Primitive Response Test
version: 1.0.0
paths:
/text:
get:
operationId: getText
responses:
'200':
description: Successful response
content:
text/plain:
schema:
type: string
/file:
get:
operationId: getFile
responses:
'200':
description: Binary response
content:
application/octet-stream:
schema:
type: string
format: binary
Generation Details
Generator:
Example CLI command:
docker run --rm \
--user "$(id -u):$(id -g)" \
-v "$SCRIPT_DIR:/local" \
openapitools/openapi-generator-cli:v7.25.0 \
generate \
-i /local/v1.0/vsat_endpoint_v1.json \
-g cpp-httplib-server \
-o /local/generated/generated_api_server_cpp_httplib
Steps to reproduce
- Create the
openapi.yaml shown above.
- Generate the server using:
--user "$(id -u):$(id -g)" \
-v "$SCRIPT_DIR:/local" \
openapitools/openapi-generator-cli:v7.25.0 \
generate \
-i /local/v1.0/vsat_endpoint_v1.json \
-g cpp-httplib-server \
-o /local/generated/generated_api_server_cpp_httplib
- Inspect the generated C++ source code.
- The generated code contains references to model headers for primitive/built-in types, for example:
#include "model/String.h"
and:
- These headers are not present in the generated project.
- Compilation therefore fails because the generated code references non-existent model classes.
Actual output vs expected output
Actual:
The generator generates/references model classes for primitive or built-in OpenAPI types.
Examples include:
#include "model/String.h"
and:
However, the OpenAPI specification does not define String or File as schemas.
As a result, the generated C++ server code contains references to non-existent headers/classes and does not compile.
Expected:
Primitive and built-in OpenAPI types should be mapped to their corresponding C++ representations without generating model classes.
For example:
should resolve to something equivalent to:
and:
schema:
type: string
format: binary
should resolve to the generator's appropriate binary/file representation without creating or referencing:
No String.h or File.h model should be generated or referenced unless the user explicitly defines corresponding schemas in the OpenAPI document.
Related issues/PRs
I have not yet identified a related issue or PR specifically covering primitive string and binary/file response schemas in the cpp-httplib-server generator.
Suggest a fix
The generator should correctly distinguish between:
- Primitive OpenAPI types (
string, integer, number, boolean, etc.)
- OpenAPI formatted primitive types such as
string/binary
- User-defined schemas/models
Primitive types should be resolved directly to their corresponding C++ types rather than being passed through the model generation mechanism.
In particular:
should resolve to the generator's C++ string type, and:
type: string
format: binary
should resolve to the appropriate binary representation.
The response type resolution and model/include generation logic should avoid producing model references such as:
#include "model/String.h"
#include "model/File.h"
when the corresponding types originate from primitive OpenAPI schemas rather than user-defined models.
Bug Report Checklist
Description
The
cpp-httplib-servergenerator incorrectly generates or references model headers for OpenAPI primitive/built-in types.In particular, responses using primitive
stringor binary/file schemas can result in generated code containing invalid model includes such as:or:
These models are not defined in the OpenAPI specification and should not be generated.
For example, a response defined as:
should be mapped to the corresponding C++ primitive type, such as
std::string, rather than a generatedStringmodel.Similarly, a binary response such as:
should be mapped to the generator's appropriate binary/file representation rather than resulting in a reference to a non-existent
model/File.h.This makes the generated server code fail to compile because the referenced model headers do not exist.
openapi-generator version
OpenAPI Generator:
7.25.0Generator:
OpenAPI version:
OpenAPI declaration file content or url
Minimal reproducible specification:
Generation Details
Generator:
Example CLI command:
docker run --rm \ --user "$(id -u):$(id -g)" \ -v "$SCRIPT_DIR:/local" \ openapitools/openapi-generator-cli:v7.25.0 \ generate \ -i /local/v1.0/vsat_endpoint_v1.json \ -g cpp-httplib-server \ -o /local/generated/generated_api_server_cpp_httplibSteps to reproduce
openapi.yamlshown above.and:
Actual output vs expected output
Actual:
The generator generates/references model classes for primitive or built-in OpenAPI types.
Examples include:
and:
However, the OpenAPI specification does not define
StringorFileas schemas.As a result, the generated C++ server code contains references to non-existent headers/classes and does not compile.
Expected:
Primitive and built-in OpenAPI types should be mapped to their corresponding C++ representations without generating model classes.
For example:
should resolve to something equivalent to:
and:
should resolve to the generator's appropriate binary/file representation without creating or referencing:
No
String.horFile.hmodel should be generated or referenced unless the user explicitly defines corresponding schemas in the OpenAPI document.Related issues/PRs
I have not yet identified a related issue or PR specifically covering primitive
stringandbinary/fileresponse schemas in thecpp-httplib-servergenerator.Suggest a fix
The generator should correctly distinguish between:
string,integer,number,boolean, etc.)string/binaryPrimitive types should be resolved directly to their corresponding C++ types rather than being passed through the model generation mechanism.
In particular:
should resolve to the generator's C++ string type, and:
should resolve to the appropriate binary representation.
The response type resolution and model/include generation logic should avoid producing model references such as:
when the corresponding types originate from primitive OpenAPI schemas rather than user-defined models.