- This repository generates SEGW ABAP classes from SAP CAP/CDS models.
- Treat this file as the operating guide for agentic coding tools working in this repo.
- Prefer small, local changes that preserve generated output shape and ordering.
- Build context from existing code before editing; do not invent project conventions.
- Primary repo-specific guidance lives in this
AGENTS.md. - No
.cursor/rules/directory is present. - No
.cursorrulesfile is present. - No
.github/copilot-instructions.mdfile is present. - If any of those files are added later, merge their instructions with this guide and follow the most specific rule for the files you touch.
src/contains the TypeScript source.src/generator/contains the high-level ABAP class generators and shared writer utilities.src/writers/contains focused emitters for entities, associations, operations, and complex types.src/converters/maps CDS and EDM types into ABAP-friendly structures.src/types/holds shared TS types and enums for ABAP, CDS, EDM, and frontend compiler data.src/utils/holds helper utilities for ABAP naming, CDS mapping, EDM mapping, and cardinality.cds-plugin.jsis the package entry point used by CAP.dist/is compiler output fromtsc; keep it synchronized withsrc/changes.test/unit/holds focused unit tests.test/integration/holds integration tests that compile inline CDS and assert generated ABAP.test/cds/is a fixture CAP project for manual plugin validation.
- Package manager:
npm. - Language: TypeScript.
- Module format: CommonJS (
"type": "commonjs"). - Compiler:
tsc. - Test runner:
jestwithts-jesttransform. - Strict type checking is enabled in
tsconfig.json. - There is currently no lint script and no ESLint/Prettier config in the repo.
- CI runs
npm testbeforenpm run build.
- Install dependencies:
npm install - Clean install matching CI:
npm ci - Build TypeScript to
dist/:npm run build - Run the full test suite:
npm test - Run Jest directly:
npx jest - Pack the module locally:
npm pack
- Run one test file through npm:
npm test -- --runTestsByPath test/unit/generator/ABAPGenerator.test.ts - Run one integration test file:
npm test -- --runTestsByPath test/integration/SegwGenerator.integration.test.ts - Run one test by name pattern:
npm test -- -t "Empty Class" - Run one file and one test name together:
npm test -- --runTestsByPath test/unit/generator/ABAPGenerator.test.ts -t "Method with RAISING exceptions" - Run Jest in watch mode locally if needed:
npx jest --watch
- Generate SEGW output from a CAP project:
cds compile srv -s all --to segw - Force OData V2 generation:
cds compile srv -s all --to segw --odata-version 2 - For local plugin testing in another CAP repo:
- Run
npm linkin this repo. - Run
npm link cap-segwin the target CAP project.
- Any runtime change under
src/should usually be followed bynpm run build. - If
src/changes affect runtime output, commit the updateddist/artifacts too. - Do not hand-edit
dist/first; editsrc/, then rebuild. - Keep generated output deterministic where possible.
- Add or update tests for behavioral changes in generators, writers, converters, or helpers.
- Prefer unit tests when a single class or helper can be exercised directly.
- Prefer integration tests when validating full CAP-to-SEGW generation behavior.
- The repo already favors inline CDS definitions in tests over fixture-heavy setups.
- Use
test/cds/mainly for manual validation, not as the default for new automated tests. - Before finishing a change, run the smallest relevant Jest command first, then broader coverage if the change is non-trivial.
- Match existing file style instead of introducing a new formatter style.
- Use tabs for indentation in TypeScript source and tests.
- Use semicolons.
- Use double quotes for TS and JS string literals unless an existing file clearly uses single quotes in a nearby block.
- Prefer trailing commas only where the surrounding file already uses them.
- Keep lines and blocks readable; do not collapse large logic into dense one-liners.
- Favor small helper methods only when they reduce duplication or isolate logic clearly.
- Keep imports at the top of the file.
- Group imports roughly by local module area as the repo already does rather than reordering aggressively.
- Existing files usually place local imports before
@sap/cds; preserve local file conventions when editing. - Prefer explicit named imports for enums, types, and CAP symbols when already used in the file.
- Use
import * as Xonly when the module is intentionally treated as a namespace, such as* as ABAP. - Do not introduce type-only import syntax unless it matches the surrounding file style.
- Keep
strictmode clean; avoid addinganyunless there is a real CAP typing gap. - When
anyis unavoidable because of CAP metadata shape, keep the cast local and narrow. - Prefer explicit return types on public methods and non-obvious private helpers.
- Use the existing type aliases and enums from
src/types/instead of duplicating literal strings. - Preserve CommonJS compatibility assumptions in build output.
- Follow the existing style for class properties: private underscore-prefixed fields are common in generators and writers.
- Classes use PascalCase, for example
ABAPGeneratorandCodeWriter. - Interfaces and interface-like generator contracts commonly use
IF...prefixes. - Enums and TS types in
src/types/use PascalCase names. - Internal class fields often use
_namestyle private properties. - Method names in TS generally use camelCase.
- Generated ABAP identifiers may intentionally use uppercase and SAP-style prefixes.
- Test files use
*.test.ts, with integration tests often using*.integration.test.ts.
- Prefer direct, readable loops and conditionals over clever abstractions.
- Existing code frequently uses
forEach,Object.keys(...).forEach, andfor...of; follow nearby style. - Preserve deterministic ordering when iterating over service entities, methods, actions, and generated outputs.
- Be careful with changes that alter generated method order, file names, or ABAP formatting.
- Keep related logic in one function unless extraction materially improves clarity.
- The current codebase rarely throws exceptions in source code.
- Prefer preserving generation flow and logging warnings when input is unusual but recoverable.
- Use
cds.log("segw")when logging within generator or writer code, matching existing patterns. - Warn for problematic model conditions such as duplicate definitions or overly long generated names.
- Throw only when continuing would produce invalid or misleading output and there is no sensible fallback.
- Do not swallow errors silently in tests; assert on them explicitly if behavior is intentional.
- This project emits ABAP code as strings; whitespace and blank lines are part of the behavior.
CodeWriteruses tab indentation and newline-terminated output; preserve that contract.- When modifying writers or generators, verify string output carefully in tests.
- Avoid introducing nondeterminism such as unstable object iteration, random data, or locale-sensitive formatting.
- Be cautious with timestamps: if changing related logic, understand whether tests or consumers rely on the current behavior.
- Use
describeandtestblocks as in the existing Jest suite. - Test names are sentence-like and usually describe observable behavior.
- Integration tests commonly build inline CDS strings, parse them with
@sap/cds, then inspect generated files/content. - Unit tests usually assert with
toContain,toEqual,toHaveLength, and similar direct matchers. - Prefer focused assertions on important generated fragments over snapshot tests.
- Add regression tests for bugs in naming, type mapping, operation generation, and ABAP formatting.
- Read the target file and nearby tests before making non-trivial changes.
- Check whether a behavior is covered by both unit and integration tests before changing it.
- Do not rename exported files, classes, or package entry points without a clear need.
- Do not add new dependencies unless the task clearly requires them.
- Do not create a lint workflow unless explicitly requested; none exists today.
- Avoid broad style-only rewrites in files with behavioral changes.
- Update
src/code minimally and consistently. - Add or update the narrowest useful tests.
- Run at least the relevant single-test command.
- Run
npm testfor broad or risky changes. - Run
npm run buildwhen runtime code changed. - Confirm
dist/matches the updatedsrc/output when applicable.
- Commit messages in repo history follow Conventional Commit style such as
fix:,test:,refactor(scope):, andchore:. - PR summaries should note behavior changes, commands run, and any ABAP output impact.
- If generation behavior changes, mention whether it affects OData V2, OData V4, or both.