Skip to content

openapi: split resolve's entry.go and resolve.go by responsibility #1094

Closed

Description

@OmarAlJarrah

Problem

#1062 left internal/resolve whole because its files each held one concern. At ff8330ba they do not:

  • entry.go (381 lines) holds a reference-or-inline entry's value, the docs written beside a use site's $ref, the hops a chain passes through, where a chain ends and the scope it is read in, and the operationId written at a pointer.
  • resolve.go (506 lines) holds the Scope, the record of reached positions, the walk of a pointer as the resolver reads it, where the lowering places what a $ref names, the pointer a $ref spells, whether two paths name one document, and the classification of a $ref site.

The tests are already split along these lines: refsite_test.go, refsite_internal_test.go, beside_test.go and holds_test.go sit beside entry_test.go and resolve_internal_test.go.

wc -l compilers/openapi/internal/resolve/{entry,resolve}.go
ls compilers/openapi/internal/resolve/*_test.go

Direction

A draft. Each declaration moves with the responsibility it serves, and a small file is fine.

File Holds
entry.go Referenced, Object, ObjectAt, found
usedocs.go siblingDocs, UseDocs
hops.go Hop, Chained, Hops
ends.go ScopeOf, End, EndOf, chained, endOf, ReferenceEnd
operationid.go OperationIDAt, walk, rawOperationID
resolve.go Scope, refuses, beside, InSource, InDocumentOf, InDocument, reached, turned, maxRefChain
reached.go Reached, NewReached, Has, note
locate.go located, locate, leave, held
placement.go Target, placed, MappingTarget
pointers.go FragmentPointer, InternalPointer, namesSelf
documents.go documentOf, SameDocument, pathRules, systemRules, sameDocument, sameAnchor, IsURL
refsite.go ComponentRef, NamesReferent, Hoistable, IsRefSite, TargetSchema

maxRefChain bounds every chain the package follows: ObjectAt, UseDocs and Hops read it, and its doc comment names endOf and Scope.reached too. It is the package's bound, so it moves beside Scope. The package comment stays at the top of resolve.go.

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 (internal/resolve/resolve.go's citation of bodySchemaPointer (content.go) is openapi: split content.go by construct #1059's).
  • 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/resolve/entry.go compilers/openapi/internal/resolve/resolve.go → 381 and 506 (morphic @ff8330ba).

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