glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.12k stars 1.06k forks source link

Missing includes in generated C++ codes. #2402

Closed black-desk closed 6 months ago

black-desk commented 12 months ago

I use quicktype to generate c++ classes from the OCI runtime spec. And I got some types that cannot be compiled without include Generators.hpp.

for examples

#pragma once

#include <optional>
#include <nlohmann/json.hpp>
#include "ocppi/runtime/config/types/helper.hpp"

namespace ocppi {
namespace runtime {
namespace config {
namespace types {
struct BlockIODeviceThrottle;
struct BlockIODeviceWeight;
}
}
}
}

namespace ocppi {
namespace runtime {
namespace config {
namespace types {
using nlohmann::json;

struct BlockIO {
std::optional<int64_t> leafWeight;
std::optional<std::vector<BlockIODeviceThrottle>> throttleReadBpsDevice;
std::optional<std::vector<BlockIODeviceThrottle>> throttleReadIOPSDevice;
std::optional<std::vector<BlockIODeviceThrottle>> throttleWriteBpsDevice;
std::optional<std::vector<BlockIODeviceThrottle>> throttleWriteIOPSDevice;
std::optional<int64_t> weight;
std::optional<std::vector<BlockIODeviceWeight>> weightDevice;
};
}
}
}
}

It seems that types in vector and map should be not only forward declared but should be included.

https://stackoverflow.com/questions/37346/why-cant-a-forward-declaration-be-used-for-a-stdvector