Skip to main content
Docs: ApiGear Core

Code Generation

The generate command creates SDKs from ObjectAPI definitions using templates. It supports solution-based generation for project workflows and expert mode for fine-grained control.

Commands​

CommandAliasDescription
generate solutiongen sol, g sGenerate from a solution file
generate expertgen xGenerate with explicit options

Solution-Based Generation​

The recommended approach uses a solution file that defines inputs, outputs, templates, and features.

Basic Usage​

apigear generate solution apigear/demo.solution.yaml

Solution File Format​

schema: "apigear.solution/1.0"
name: my_project
version: "1.0.0"

targets:
- name: cpp_sdk
inputs:
- myapi.module.yaml
output: ../generated/cpp
template: apigear-io/template-cpp14@v3.6.0
force: true
features:
- api
- stubs
- olink

Solution Options​

FieldDescription
nameTarget identifier
inputsList of module files (YAML or IDL)
outputOutput directory (relative to solution file)
templateTemplate name with optional version
forceOverwrite existing files (default: false)
featuresList of template features to enable

Watch Mode​

Automatically regenerate when the solution file changes:

apigear generate solution demo.solution.yaml --watch

Force Overwrite​

Override the solution's force setting:

apigear generate solution demo.solution.yaml --force

Expert Mode​

For quick generation without a solution file, use expert mode with explicit options.

Basic Usage​

apigear generate expert -i demo.module.yaml -o output -t apigear-io/template-cpp14

Expert Options​

FlagShortDescriptionDefault
--input-iInput module files (required)["apigear"]
--output-oOutput directory (required)"out"
--template-tTemplate to use (required)"tpl"
--features-fFeatures to enable["all"]
--force—Overwrite existing filesfalse
--watch—Watch for changesfalse

Multiple Inputs​

apigear generate expert \
-i api/user.module.yaml \
-i api/inventory.module.yaml \
-o generated \
-t apigear-io/template-cpp14

Enabling Features​

apigear generate expert \
-i demo.module.yaml \
-o output \
-t apigear-io/template-cpp14 \
-f api \
-f stubs \
-f olink

Using Local Templates​

Point to a local template directory:

apigear generate expert \
-i demo.module.yaml \
-o output \
-t ./my-custom-template

Template Versioning​

Latest Version​

Without a version specifier, the latest version is used:

apigear generate expert -t apigear-io/template-cpp14 ...

Specific Version​

Pin to a specific version using @version:

apigear generate expert -t apigear-io/template-cpp14@v3.6.0 ...
# In solution file
template: apigear-io/template-cpp14@v3.6.0
tip

Always specify versions in production to ensure reproducible builds.

Multiple Targets​

A solution can generate multiple SDKs from the same API:

targets:
- name: cpp_sdk
inputs:
- myapi.module.yaml
output: ../generated/cpp
template: apigear-io/template-cpp14@v3.6.0
features:
- api
- stubs

- name: python_sdk
inputs:
- myapi.module.yaml
output: ../generated/python
template: apigear-io/template-python@v1.0.0
features:
- api
- stubs

- name: unreal_sdk
inputs:
- myapi.module.yaml
output: ../generated/unreal
template: apigear-io/template-unreal@v3.2.2
features:
- api
- stubs

Common Features​

Most templates support these features:

FeatureDescription
apiGenerate interface definitions
stubsGenerate implementation stubs
scaffoldGenerate complete project structure
olinkEnable ObjectLink protocol support
mqttEnable MQTT protocol support
monitorEnable API monitoring

Check individual template documentation for available features.

Input Formats​

YAML Format​

# demo.module.yaml
schema: apigear.module/1.0
name: demo
version: "1.0.0"

interfaces:
- name: Counter
properties:
- name: count
type: int
operations:
- name: increment
- name: decrement

IDL Format​

// demo.idl
module demo 1.0

interface Counter {
count: int
increment()
decrement()
}

Both formats can be used interchangeably in inputs.

Output Structure​

Generated output follows the template's structure. A typical C++ output:

generated/
├── CMakeLists.txt
├── demo/
│ ├── api/
│ │ ├── counter.h
│ │ └── counter.cpp
│ ├── implementation/
│ │ ├── counter.h
│ │ └── counter.cpp
│ └── olink/
│ ├── counter_service.h
│ └── counter_client.h
└── README.md

CI/CD Usage​

# Install specific template version
apigear template install apigear-io/template-cpp14@v3.6.0

# Generate with pinned versions
apigear generate solution apigear/solution.yaml

# Check exit code
if [ $? -ne 0 ]; then
echo "Generation failed"
exit 1
fi

Troubleshooting​

Template Not Found​

Error: template not found: apigear-io/template-cpp14

Install the template first:

apigear template install apigear-io/template-cpp14

Invalid Module​

Error: invalid module: demo.module.yaml

Validate the module:

apigear spec check demo.module.yaml

Output Directory Exists​

By default, existing files are not overwritten. Use --force or set force: true in the solution.