ORE Studio Codegen
Basic code generation support for ORE Studio.
Instructions
Codegen is simple code generator that uses JSON models and Mustache templates to generate code.
Setup
- Install dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Usage
Run the code generator using the provided script:
./run_generator.sh <model_path> [output_dir]
Examples:
# Using default output directory (output/) ./run_generator.sh models/slovaris/catalogs.json # Using custom output directory ./run_generator.sh models/slovaris/catalogs.json custom_output/
Overall Models (Batch Execution)
You can define an overall model.json that references multiple files. The generator
will automatically process all dependent models first.
./run_generator.sh models/slovaris/model.json
Using Profiles
Profiles allow you to generate all templates for a specific facet in one command.
Profiles are defined in library/profiles.json.
# List available profiles ./run_generator.sh --list-profiles # Generate all Qt UI components for a domain entity ./run_generator.sh models/dq/dataset_bundle_domain_entity.json output/ --profile qt # Generate all C++ domain facets (domain type, repository, service, protocol) ./run_generator.sh models/dq/some_schema.json output/ --profile all-cpp # Generate SQL schema files ./run_generator.sh models/dq/dataset_bundle_domain_entity.json output/ --profile sql
Available profiles:
| Profile | Description | Model Types |
|---|---|---|
sql |
SQL schema creation scripts | domain_entity, junction |
qt |
Qt UI components (model, window, dialogs, controller) | domain_entity |
protocol |
Messaging protocol (request/response) | domain_entity, schema |
domain |
Domain types (class, JSON I/O, table) | schema |
generator |
Fake data generators for testing | schema |
repository |
Repository layer (entity, mapper, CRUD) | schema |
service |
Service layer | schema |
all-cpp |
All C++ facets combined | schema |
plantuml |
PlantUML ER diagrams | schema, data |
Slovaris Generation
A dedicated script is provided to generate all Solvaris artefacts and place them
in the correct location in the ores.sql project:
./generate_slovaris.sh
Architecture
src/- Python source code for the generatorlibrary/data/- Static data files (licenses, modelines, etc.)library/templates/- Mustache templatesmodels/- JSON model filesoutput/- Default directory for generated files
Key Features
- Overall Models: Support for
model.jsonfiles that orchestrate the generation of multiple artefacts. - Dynamic Prefixing: Use the
model_nameproperty in an overall model to prefix all output files (e.g.,solvaris_). - Automatic Sibling Loading: Sibling JSON models in the same directory are automatically loaded and available for cross-referencing in templates.
- Enhanced Data Context: Identifies specific datasets by subject area (e.g.,
currencies_dataset,countries_dataset) for easy template access. - License & Modelines: Automatically generates license headers with proper editor modelines.
Model-Template Mapping
The generator maps model files to templates based on their filenames:
model.json→sql_batch_execute.mustachecatalogs.json→sql_catalog_populate.mustachecountry_currency.json→sql_flag_populate.mustache,sql_currency_populate.mustache,sql_country_populate.mustachedatasets.json→sql_dataset_populate.mustache,sql_dataset_dependency_populate.mustachemethodologies.json→sql_methodology_populate.mustachetags.json→sql_tag_populate.mustache
Extending
To add a new model-template pair:
- Add your JSON model to the
models/directory - Add your Mustache template to
library/templates/ - Update the mapping in
src/generator.pyin theget_template_mappings()function