OpenAPITools / OpenAPITools/openapi-generator
[BUG][cpp-httplib-server] Top-level enum schema via $ref generates empty class with no enum members
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?
Description
When a top-level schema is defined as type: string with enum values and referenced via $ref, the cpp-httplib-server generator emits a class with only toJson() / fromJson() accessors but no actual enum class members and no enum values. The class is entirely hollow and cannot be used.
Inline enum definitions (defined directly on a property rather than in components/schemas) work correctly, but this is not acceptable when the same enum type is reused across multiple locations in the spec — deduplication via $ref is the correct OpenAPI pattern.
openapi-generator version
7.22.0
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
title: Enum Bug Reproduction
version: "1.0.0"
paths:
/example:
get:
operationId: getExample
parameters:
- in: query
name: status
schema:
$ref: '#/components/schemas/StatusEnum'
responses:
'200':
description: OK
components:
schemas:
StatusEnum:
type: string
enum:
- ACTIVE
- INACTIVE
- PENDING
Generation Details
Generated class has no member variables:
/**
* This file is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#pragma once
// System headers
#include <nlohmann/json.hpp>
namespace models {
class StatusEnum
{
public:
StatusEnum();
virtual ~StatusEnum() = default;
// Getters and setters
// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(StatusEnum,
)
private:
};
} // namespace models
Expected output: should have created an enum class with ACTIVE, INACTIVE and PENDING.
Steps to reproduce
docker run --rm -v $PWD:/local openapitools/openapi-generator-cli:v7.22.0 generate -g cpp-httplib-server -i local/test.yml -o ./local/out
Related issues/PRs
#958 — Similar symptom on cpp-restsdk
#10301 — $ref enum causes compilation error on cpp-restsdk
Suggest a fix
It seems that the cpp-httplib codegen is missing handling for top-level enums, as other C++ generators don't have this problem.
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
Reproduce the issue with the provided local/test.yml using the cpp-httplib-server generator Docker command, then inspect the generated StatusEnum class. Start by locating the cpp-httplib-server generator templates or entry points responsible for top-level schemas and compare the output with inline enums. Done means a $ref-backed StatusEnum contains ACTIVE, INACTIVE, and PENDING and remains usable in generated C++ code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100