Skip to content

docs: model-layer codegen design specifications#138

Draft
OmarAlJarrah wants to merge 1 commit into
mainfrom
docs/codegen-model-layer-design
Draft

docs: model-layer codegen design specifications#138
OmarAlJarrah wants to merge 1 commit into
mainfrom
docs/codegen-model-layer-design

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Adds a docs/codegen/ directory of design specifications for the planned model-layer code generator. These are design documents only — no generator code, no KotlinPoet templates, and no generated sources are added. Every Kotlin/Java snippet is clearly labeled as illustrative target output showing the shape a future generator would emit, grounded in the real sdk-core API (Tristate, the Serde SPI, Paginator, RequestBody, and the TristateModule adapter pattern).

The unifying principle, matching how sdk-core is already built: logic lives in a hand-written runtime, generated code stays thin.

What's included

  • json-field-model.md — the foundation. A dependency-free four-state field wrapper JsonField<T> (Known / Missing / Null / Raw) plus an embedded RawJson tree, with all Jackson conversion kept behind the Serde SPI in the adapter, mirroring how Tristate is split today. Documents the read-path (forward-compat) vs PATCH-path (three-state) boundary so JsonField and Tristate are never wrongly merged.
  • model-classes.md — generated models as a field map plus one-line typed accessors over a hand-written JsonModel runtime that carries the invariant machinery. Includes an explicit coverage strategy (module-scoped Kover exclusion from the aggregate floor) and binary-compatibility strategy (a separate .api baseline for generated code).
  • model-validation.md — an opt-in, memoized, fail-soft validate() / isValid() / validity() triad that is never invoked on the deserialize path, used only as the fallback union-disambiguation strategy behind discriminator matching.
  • discriminator-const-fields.md — const and discriminator fields generated as defaulted raw values with dual (typed + raw) accessors.

A docs/codegen/README.md index ties the specs together and is linked from the repository README documentation table.

Notes

The four-state field model is the foundation the other three specs build on; the dependency order is captured in the index. apiDump / build steps are out of scope here since this PR adds only Markdown.

Closes #51
Closes #64
Closes #65

Add a docs/codegen/ directory of design specifications for the planned
model-layer code generator. These are design documents only — no generator
or generated code is added to the repository.

- json-field-model.md: a dependency-free four-state JSON field wrapper
  (JsonField<T>: Known / Missing / Null / Raw) plus an embedded RawJson
  tree, with all Jackson conversion kept behind the Serde SPI in the
  adapter, mirroring how Tristate is split. Documents the read-path
  (forward-compat) vs PATCH-path (three-state) boundary so JsonField and
  Tristate are never wrongly merged.
- model-classes.md: generated models as a field map plus one-line typed
  accessors over a hand-written runtime that owns the invariant machinery,
  with an explicit coverage (module-scoped Kover exclusion) and
  binary-compatibility (separate .api baseline) strategy for generated code.
- model-validation.md: an opt-in, memoized, fail-soft validate()/isValid()/
  validity() triad that is never run on the deserialize path and serves as
  the fallback union-disambiguation strategy behind discriminator matching.
- discriminator-const-fields.md: const and discriminator fields generated as
  defaulted raw values with dual (typed + raw) accessors.

Add a docs/codegen/README.md index and link it from the repository README
documentation table.
@OmarAlJarrah OmarAlJarrah marked this pull request as draft June 17, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant