Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ for debugging purposes.
- `-r`: Alias for `--require`.
- `--preferred-identifier <uri> <identifier>`: Sets the preferred identifier for a schema.
- `-p`: Alias for `--preferred-identifier`.

- `--namespace <namespace>`: Sets the default global namespace for generated files.
- `-n`: Alias for `--namespace`.
- `--no-namespace`: Disables generation of namespaces.
- `-nn`: Alias for `--no-namespace`.
27 changes: 17 additions & 10 deletions include/SyncedSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SyncedSchema {
public:
using Type = IndexedSyncedSchema::Type;
using Format = IndexedSyncedSchema::Format;
std::reference_wrapper<const CodeProperties> codeProperties =
std::reference_wrapper<const CodeProperties> codeProperties_ =
std::cref(getDefaultCodeProperties());

std::string identifier_;
Expand Down Expand Up @@ -68,9 +68,11 @@ class SyncedSchema {

std::optional<std::vector<nlohmann::json>> examples_;

SyncedSchema(const std::string& identifier)
: identifier_(identifier), arrayProperties_(getTrueSchema()),
objectProperties_(getTrueSchema()) {}
SyncedSchema(
const std::string& identifier, const SyncedSchema& trueSchema,
const CodeProperties& codeProperties = getDefaultCodeProperties())
: codeProperties_(codeProperties), identifier_(identifier),
arrayProperties_(trueSchema), objectProperties_(trueSchema) {}

private:
/// @brief Private constructor to create default schemas
Expand Down Expand Up @@ -99,15 +101,20 @@ class SyncedSchema {
return properties;
}

static const SyncedSchema& getTrueSchema() {
static SyncedSchema schema;
schema.identifier_ = "True";
schema.definedAsBooleanSchema_ = true;
static std::unique_ptr<SyncedSchema> getTrueSchema(
const CodeProperties& codeProperties = getDefaultCodeProperties()) {
auto schema = std::make_unique<SyncedSchema>(SyncedSchema());
schema->codeProperties_ = codeProperties;
schema->identifier_ = "True";
schema->definedAsBooleanSchema_ = true;
schema->arrayProperties_ = ArrayProperties(*schema);
schema->objectProperties_ = ObjectProperties(*schema);
return schema;
}

static std::vector<std::unique_ptr<SyncedSchema>>
resolveIndexedSchema(std::vector<IndexedSyncedSchema>&& schemas);
static std::vector<std::unique_ptr<SyncedSchema>> resolveIndexedSchema(
std::vector<IndexedSyncedSchema>&& schemas,
const CodeProperties& codeProperties = getDefaultCodeProperties());

static void dumpSchemas(std::vector<std::unique_ptr<SyncedSchema>>& schemas,
std::filesystem::path outputDirectory = ".");
Expand Down
3 changes: 2 additions & 1 deletion include/SyncedSchema/ArrayProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct ArrayProperties {
ArrayProperties(const SyncedSchema& items) : items_(items) {}
ArrayProperties(
const IndexedArrayProperties& arrayProperties,
const std::vector<std::unique_ptr<SyncedSchema>>& syncedSchemas);
const std::vector<std::unique_ptr<SyncedSchema>>& syncedSchemas,
const SyncedSchema& trueSchema);

/// @brief Gets the C++ type of the array
std::string getArrayType(std::string namespaceLocation) const;
Expand Down
Loading