Skip to content

openapi: schema re-exports three annotation calls that operation can make itself #1092

Closed

Description

@OmarAlJarrah

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 -l

schema/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, ExtensionsOf and ExtensionsIn, and have their callers call annotation as the other thirty sites do.
  • Move AppendExample into operation (into content.go for now; openapi: split content.go by construct #1059 gives examples a file of their own). Its two tests in schema/schema_test.go, which call schema.AppendExample, move with it into operation's tests.
  • Keep PreserveSchemaKeyword, PreserveUnknownKeywords, preserve and preserveKeyword. They carry logic about schema keywords, such as undefinedKeywords reading the nullable-widening policy, and params.go uses them for a parameter's schema keywords.
  • Rewrite the header comment of accumulate.go, which lists what operation reaches in schema, 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/schema finds 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).

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