Skip to content

fix: preserve Go allOf object composition - #181

Open
adamcavendish wants to merge 1 commit into
mainfrom
adamcavendish/go-allof-composition
Open

adamcavendish wants to merge 1 commit into
mainfrom
adamcavendish/go-allof-composition

Conversation

@adamcavendish

Copy link
Copy Markdown
Collaborator

Summary

Generate compiling, flat-wire Go allOf object/map models while retaining named
member entrypoints. Add a raw JSON escape hatch for compositions that cannot be
represented conservatively as objects.

Problem

The Go emitter embedded every intersection member, including anonymous maps,
producing invalid map[string]any struct fields. Merely naming the map is not
enough: JSON methods promoted from one embedded object can hide sibling fields.

Behavior

Situation Behavior
Object/map composition Explicit JSON methods produce one flat object
Named and aliased members Keep embedded member entrypoints and promoted fields
Anonymous or repeated members Named storage with collision-safe suffixes
Declared versus extension keys Member projection prevents stale map copies
Conflicting member writes Return an error instead of overwriting JSON encodings
Repeated composition graphs Cache and deduplicate resolved metadata
Unsupported composition Preserve JSON with a json.RawMessage alias
all_of_strategy = "raw" Use raw JSON for every intersection

Compatibility

The default composed policy follows retained object/map facts through aliases
and nested intersections. Existing named member struct literals and field access
remain available; anonymous map storage was previously uncompilable. Duplicate
member names receive suffixes instead of invalid duplicate embeddings.

Non-object, incompatible and unproductive cyclic intersections now use
json.RawMessage; consumers of those previous representations should regenerate
and update their construction code. Explicit raw mode intentionally does not
enforce intersection constraints and retains JSON kinds, nulls and exact numbers.

This is conservative representation planning, not a complete JSON Schema
validator. Ordinary member codecs, null/optional handling and Go's dynamic any
floating-point behavior remain unchanged. Conflicting writes are compared by
their JSON encodings rather than by a schema-level equivalence relation.

Boundaries

Go only. Shared lowering, ordinary object/dictionary codecs, untagged unions,
JVM composition, generated dependencies and generation formatting are unchanged.
Native consumers run directly through the Go golden-build entrypoint without
patching generated source or spawning build tools from tests.

- Compose compatible object and map members as flat JSON instead of embedding
  anonymous map syntax that cannot compile or inheriting a sibling-hiding codec.
- Retain named member entrypoints and promoted fields, naming anonymous maps and
  disambiguating repeated members and storage collisions without wire wrappers.
- Project declared keys to their owning members so extension maps do not retain
  stale copies, and reject conflicting member encodings instead of overwriting.
- Follow aliases and nested object facts with cached, deduplicated metadata so
  repeated composition references do not expand every path through the graph.
- Offer composed and raw policies, preserving non-object, incompatible and cyclic
  intersections as json.RawMessage rather than emitting invalid or lossy models.
- Retain ordinary encoding/json member behavior and typed HTTP request, success
  and lazy error payloads through structured model and method emission.
- Run native Go consumers through the golden build entrypoint alongside exact
  render, versioned IR and golden contracts on untouched generated projects.
- Keep ordinary object and dictionary codecs, shared lowering, other generators,
  generated dependencies and formatting redesign outside this Go repair.
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.21790% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/generators/go/http/composition.rs 91.86% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant