Skip to content

openapi: split schema lowering into one file per construct #1060

Closed

Description

@OmarAlJarrah

Problem

In compilers/openapi/internal/schema:

  • compose.go (1,588 lines) holds four constructs in sequence: lowerAllOf at line 41, lowerOneOfAnyOf at 549, lowerDiscriminator at 1136 and lowerEnum at 1382.
  • schema.go (2,420 lines) holds dispatch beside the keyword census, models, scalars, $dynamicRef and nullability.
  • resolve.go lowers a $ref site, although resolving references is internal/resolve's job.
  • discriminated.go and enummember.go hold halves of constructs whose other halves sit in compose.go.
  • The naming hints for a hoisted node are split between resolve.go and compose.go, each calling the other.

allOf's tests are split too: 39 TestAllOf_* in compose_test.go, 16 in schema_test.go.

Direction

File Holds
allof.go allOf composition, its required lists and false branches
union.go oneOf/anyOf, null-only and distributed unions, siblings beside a union
discriminator.go discriminators, mappings, a subtype's discriminator value (absorbs discriminated.go)
enum.go enums and const unions (absorbs enummember.go)
census.go which keywords a lowering homes and what it keeps verbatim
model.go models, properties, additional and pattern properties, tuples, arrays (lowerArray leaves accumulate.go)
scalar.go scalars, formats, content encoding
dynamicref.go $dynamicRef expansion and the anchor index
nullable.go whether a schema admits null
refsite.go the $ref site (was resolve.go)
hoist.go gains the naming hints for a hoisted node, the inline-hoisting rule's other half
schema.go keeps the entry, dispatch, component declarations and shared readers
  • Tests follow their names. foreign_test.go, mapping_raw_targets_test.go, unhomed_discriminator_test.go, reasons_internal_test.go and fix(compilers/openapi): flatten a nested inline allOf #998's compose_equivalence_test.go merge into the files of the constructs they test.
  • Comments that name a file: FillPropertyDetail (schema.go) in internal/annotation; the compose.go path in compilers/openapi/amplification_test.go; and the note in accumulate.go about what operation reaches in schema.go, which is re-derived, not just re-pointed.

Blocked by

Done when

  • Every top-level declaration of the package, with its doc comment and any comment between declarations, is byte-identical before and after the move (compared with a throwaway go/ast script), and no golden changes.
  • Comments that name a file name the file the code now lives in, changed in a commit of their own.
  • go test ./compilers/openapi/... passes without -update.

Priority: P4, rule 1 (housekeeping: moves code between files and changes no lowering, validation, IR or emit-contract behaviour). wc -l compilers/openapi/internal/schema/{compose,schema}.go → 1588, 2420 (morphic @a1f15b29).

Activity

  1. added
    type:choreRefactor or cleanup, no behavior change
    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formats
    on Oct 21, 2026
  2. OmarAlJarrah commented on Oct 22, 2026

    @OmarAlJarrah
    MemberAuthor

    #1100 changes two things this plan names in schema/accumulate.go:

    • The header no longer lists what operation reaches in schema. It states which preservation functions belong in schema at all: only one whose decision needs the lowering, and it names PreserveUnknownKeywords as that one. It names no file, so the move only has to keep it beside the code it describes rather than re-derive a list.
    • What is left in the file is PreserveUnknownKeywords, undefinedKeywords and lowerArray. AppendExample, PreserveSchemaKeyword and the forwarders moved to annotation or were deleted, so they no longer need a file here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:choreRefactor or cleanup, no behavior change

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions