Repository navigation
openapi: schema re-exports three annotation calls that operation can make itself #1092
Description
Problem
internal/annotation takes a provenance function so it can stay below lowering, and callers pass c.ProvenanceAt to it. Thirty call sites do that directly, in auth, operation, schema, meta.go and servers.go:
git grep -nE 'annotation\.[A-Za-z]+\(.*ProvenanceAt' -- compilers/openapi ':!*_test.go' ':!compilers/openapi/internal/schema/accumulate.go' | wc -lschema/accumulate.go also re-exports three of those calls under names of its own:
| Re-export | Forwards to | Call sites |
|---|---|---|
PreserveNode |
annotation.PreserveNodeInto(…, c.ProvenanceAt(pointer)) |
16 in operation, 2 in schema |
ExtensionsOf |
annotation.ExtensionsFrom(ext, c.ProvenanceAt, owner) |
6, all in operation |
ExtensionsIn |
annotation.ExtensionsUnder(ext, c.ProvenanceAt, owner, scope) |
5, all in operation |
So one call has two spellings: auth and servers.go write annotation.ExtensionsFrom(…, c.ProvenanceAt, …), while operation writes schema.ExtensionsOf(c, …). It also makes operation look as though it depends on schema lowering where it does not. AppendExample has logic of its own, but only operation/content.go calls it, for media type, header and parameter examples.
Direction
- Delete
PreserveNode,ExtensionsOfandExtensionsIn, and have their callers callannotationas the other thirty sites do. - Move
AppendExampleintooperation(intocontent.gofor now; openapi: split content.go by construct #1059 gives examples a file of their own). Its two tests inschema/schema_test.go, which callschema.AppendExample, move with it intooperation's tests. - Keep
PreserveSchemaKeyword,PreserveUnknownKeywords,preserveandpreserveKeyword. They carry logic about schema keywords, such asundefinedKeywordsreading the nullable-widening policy, andparams.gouses them for a parameter's schema keywords. - Rewrite the header comment of
accumulate.go, which lists whatoperationreaches inschema, from the code as it then stands.
A new package for this plumbing was considered and is not proposed: annotation already is the plumbing, and a package over it would add a third spelling.
Done when
git grep -nE 'func (PreserveNode|ExtensionsOf|ExtensionsIn|AppendExample)\(' -- compilers/openapi/internal/schemafinds nothing.- Goldens, the harness sweep over
testdata/and every diagnostic are unchanged. go test ./compilers/openapi/...passes without-update.
Blocks #1059 and #1060, whose moves would otherwise carry the re-exports and the stale header.
Priority: P4, rule 1 (housekeeping that unblocks #1059 and #1060). The command above → 30; git grep -cE 'schema\.(PreserveNode|ExtensionsOf|ExtensionsIn)\(' -- compilers/openapi/internal/operation → 27 call sites over 6 files (morphic @ff8330ba).
Activity