# SnippetBase

CLASS in `@skmtc/core 0.63.4`

Abstract root of every stringifiable element in the SKMTC DSL.

Two specializations live below this class:

- **Projections** - named, exportable artifacts built by the
  projection-base factories (`toModelProjectionBase` and the operation
  and webhook siblings) on a language package's snippet base; the pipeline wraps
  them in a `Definition` and registers them in a file.
- **Snippets** are anonymous, embedded values whose `toString()` is spliced
  into the body of a Projection (or another Snippet). `Definition` and
  `CustomValue` extend `SnippetBase` directly without going through a
  Projection base.

`SnippetBase` is **language-blind**: it has no `register`, no language,
and nothing on it can throw for lack of identity. Register ergonomics
live on each language package's snippet base (e.g. `TsSnippet`'s
`register`, which delegates to that package's register function) - a raw
`SnippetBase` subclass that tries to register is a compile-time error.
`generatorKey` and `stackTrail` are *optional* attribution inputs only.


**Attribution (gen-maps)**


In a run that captures a render (`context.capturesRender`: attribution
emission is configured), every instance self-wraps its `toString` at
construction (an own-property wrapper - shared function,
non-enumerable). In any other run no instance has a wrapper, and
`toString` is the subclass's own. The wrapper is
gated by the **capture interval**: the span while
`GenerateContextType.captureSink`
is set, which `RenderContext` opens around the one capturing render and
closes in `finally`. Inside the interval each `toString` invocation is
observed into the transient
`CaptureSink` occurrence tree;
outside it the wrapper is a pure pass-through. Subclass authors write
nothing different. Snippets constructed *during* the capture render are
captured too - they self-wrap at birth.

One documented convention: declare `toString` as a prototype method,
never as an instance field (an arrow-function field would overwrite the
wrapper).

## Signature

```ts
import { SnippetBase } from '@skmtc/core'

class SnippetBase
```

## Constructor

### constructor

```ts
constructor(args: SnippetBaseArgs)
```

## Properties

- `context` (GenerateContextType): The generation context providing access to OAS objects and utilities
- `skipped` (boolean): Whether this generator has been skipped
- `generatorKey` (GeneratorKey | undefined): Optional generator key - attribution input only
- `stackTrail` (StackTrail): Position of the schema fragment this snippet was built from, as a `StackTrail`. Callers pass a stable snapshot (a **clone** taken at the call site - `StackTrail` is mutable, so an un-cloned reference would alias a trail that later append/remove calls could mutate). The empty trail (`StackTrail.empty()`) means "no single originating node", in which case the resolver uses the generator-key-derived pointer. Converted to a JSON Pointer string only at the resolver - never carried as a string here.
