OpenAPITools / OpenAPITools/openapi-generator
[BUG] [cpp-httplib-server] Primitive and binary response types incorrectly generated as models
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-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:
#include "model/File.h"
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:
cpp-httplib-server
OpenAPI version:
3.1.0
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:
cpp-httplib-server
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.yamlshown 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:
#include "model/File.h"
- 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:
#include "model/File.h"
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:
schema:
type: string
should resolve to something equivalent to:
std::string
and:
schema:
type: string
format: binary
should resolve to the generator's appropriate binary/file representation without creating or referencing:
model/File.h
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:
type: string
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.
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
Start by reproducing the issue with the minimal OpenAPI 3.1.0 specification and the cpp-httplib-server generator command described in the report. Trace the response type resolution and model/include generation logic for primitive string and binary schemas. Done means generated server code uses appropriate C++ representations and no longer references nonexistent String.h or File.h models.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100