cap-mock-generator
v1.0.11
Published
An interactive mock data generation engine for SAP CAP applications, leveraging the official @sap/cds-compiler by SAP for schema parsing.
Maintainers
Readme
CAP Mock Generator
An advanced, interactive, and intelligent mock dataset generation engine built specifically for SAP Business Technology Platform (BTP) Cloud Application Programming Model (CAP) applications.
cap-mock-generator parses your native .cds schemas and populates your db/data/ folder with highly realistic, relationally consistent .csv mock files in seconds, using either a cutting-edge AI Smart Layer or a high-speed Local Fallback Engine.
Features
- Interactive Onboarding Wizard: Powered by modern
@inquirer/prompts, walking you seamlessly through configuration step-by-step. - Relational Data Integrity (Foreign Key Management): Automatically analyzes dependencies. It ensures child tables (e.g., entity relationships ending with
ID) match valid, existing primary keys generated from parent tables. - Automatic Virtual Column Stripping: Cleanly filters out
Association to manyandComposition of manyvirtual elements so they never mess up your physical CSV deployment files. - Multi-Provider AI Data Layer: High-fidelity business mock data using either Google Gemini Pro (
gemini-2.5-flash) or OpenAI (gpt-4o-mini) structured JSON responses. - Resilient Fallback Core: If your AI API tokens hit limit caps or encounter network spikes (503 Service Unavailable), the engine gracefully falls back to a lightning-fast local Faker.js cluster without crashing.
- Clean Architectural Foundations: Designed around the Command-Service pattern for maximum scalability and maintainability.
Installation
You can install cap-mock-generator globally, locally as a development dependency, or invoke it instantly on-demand using npx.
1. Global Installation
Quickest access across any project workspace:
npm install -g cap-mock-generator2. Local Installation
Recommended for engineering team standardization.
Install it directly as a development dependency inside your specific SAP CAP project root directory:
npm install cap-mock-generator --save-devUsage
Once installed, open your terminal, ensure you are in the root directory of your SAP CAP application where your package.json and db/ folder reside, and trigger the wizard using one of the strategies below.
Option A: On-The-Fly Execution
No installation required.
If you prefer to run the module directly without explicitly downloading it to your machine, use npx:
npx cap-mock-generator startOption B: Global Command Line Execution
If you selected the global installation strategy earlier, simply ignite the interface by typing:
cap-mock-generator startOption C: Configured Local Project Scripts
If you installed the generator locally, open your native package.json and map a clean entry shortcut helper to your internal scripts block:
{
"scripts": {
"mock:gen": "cap-mock-generator start"
}
}Now, any team member working on the repository can securely refresh testing data vectors by executing:
npm run mock:genInteractive Onboarding Flow
When you ignite the CLI wizard, it will guide you through the following prompts:
🌟 --- CAP Mock Generator Onboarding Wizard ---
? Enter your CDS schema filename inside the "db" directory: (schema.cds)
? How many mock records should be generated per Entity? (5)
? Do you want to enable the AI smart data layer engine? (Yes/No)
? Select your preferred AI Provider target: (Gemini (Google) / OpenAI (GPT))
? Provide your secret authorization API Key: ***********************
⚙️ Processing schema and initializing execution...
🔍 Analyzing model artifacts...
📦 Processing Entity: [sap.btp.assetmanagement.Plants]
🤖 Generating smart context data via Gemini...
✅ CSV successfully exported to: .../db/data/sap.btp.assetmanagement.Plants.csv
📦 Processing Entity: [sap.btp.assetmanagement.Assets]
🤖 Generating smart context data via Gemini...
✅ CSV successfully exported to: .../db/data/sap.btp.assetmanagement.Assets.csv
✨ Execution successfully completed! Check your db/data directory. 😎Security & Environment Compliance
Your secret API credentials, such as GEMINI_API_KEY or OPENAI_API_KEY, are processed strictly inside your immediate shell execution context memory through process.env.
They are never saved to disk, logged to the console, or transported outside the official provider endpoint requests.
Relational Schema Topology
The generator intelligently tracks schema hierarchy. Take this complex manufacturing scenario:
entity Plants {
key ID : UUID;
name : String(100);
}
entity Assets {
key ID : UUID;
plantID : UUID; // Foreign Key referencing Plants
name : String(100);
}License and Usage Notice
This library leverages the official @sap/cds-compiler package provided by SAP to parse CDS schema definitions for SAP CAP applications. It does not modify, bundle, or redistribute SAP source code beyond declaring @sap/cds-compiler as an npm dependency.
The @sap/cds-compiler package is provided under SAP's own license terms. Users of cap-mock-generator are responsible for reviewing and complying with the applicable SAP license terms when using this package in projects that depend on SAP CAP tooling.
Careful attention should be paid to licensing restrictions when integrating cap-mock-generator into commercial, enterprise, or redistributed software that includes SAP CAP dependencies.
cap-mock-generator itself is licensed under the MIT License. See the LICENSE file for details.
