quicktype
quicktype copied to clipboard
[BUG]: Wrong c++ code generation
Incorrect c++ code generation
Issue Type
quicktype output via cli is incorrect was output a hpp (c++) files.
Context
Windows 11,
Input Format: json schema Output Language: c++
CLI Version: 23.0.171
Description
I'm encountering unexpected output when running the following quicktype CLI command:
quicktype `
--out "Student.hpp" `
--lang c++ `
--top-level Student `
--src "student.schema.json" `
--code-format with-struct `
--type-style camel-case `
--member-style camel-case `
--enumerator-style pascal-case `
--no-boost
Input Data
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"firstName": { "type": "string" },
"lastName": { "type": "string" },
"age": { "type": "integer" },
"gender": { "enum": ["Male", "Female"] }
},
"required": ["firstName", "lastName", "age"]
}
Current Output
#pragma once
#include "json.hpp"
namespace quicktype {
using nlohmann::json;
#ifndef NLOHMANN_UNTYPED_quicktype_HELPER
#define NLOHMANN_UNTYPED_quicktype_HELPER
inline json get_untyped(const json & j, const char * property) {
if (j.find(property) != j.end()) {
return j.at(property).get<json>();
}
return json();
}
inline json get_untyped(const json & j, std::string property) {
return get_untyped(j, property.data());
}
#endif
struct age {
std::string type;
};
struct gender {
std::vector<std::string> genderEnum;
};
struct properties { // what is this??
age firstName;
age lastName;
age age;
gender gender;
};
struct student {
std::string schema;
std::string type;
properties properties;
std::vector<std::string> required;
};
}
...
Issues Observed:
Inconsistent CLI vs Web App Output:
The generated C++ code differs between the CLI tool and the web app. Incorrect Schema Interpretation:
The age and gender fields are not being correctly represented as expected. The properties struct is structured strangely. Constraint Handling Issues:
Adding constraints (e.g., minimum and maximum for age) does not work as expected. Any insights into why this is happening and how to resolve it?