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

  1. 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 generator
  • library/data/ - Static data files (licenses, modelines, etc.)
  • library/templates/ - Mustache templates
  • models/ - JSON model files
  • output/ - Default directory for generated files

Key Features

  • Overall Models: Support for model.json files that orchestrate the generation of multiple artefacts.
  • Dynamic Prefixing: Use the model_name property 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.jsonsql_batch_execute.mustache
  • catalogs.jsonsql_catalog_populate.mustache
  • country_currency.jsonsql_flag_populate.mustache, sql_currency_populate.mustache, sql_country_populate.mustache
  • datasets.jsonsql_dataset_populate.mustache, sql_dataset_dependency_populate.mustache
  • methodologies.jsonsql_methodology_populate.mustache
  • tags.jsonsql_tag_populate.mustache

Extending

To add a new model-template pair:

  1. Add your JSON model to the models/ directory
  2. Add your Mustache template to library/templates/
  3. Update the mapping in src/generator.py in the get_template_mappings() function