Documentation
¶
Overview ¶
Package common holds shared per-Builder state every concrete per-decl builder (schema, parameters, responses, routes, operations, spec) embeds. See [./README.md](./README.md) for the long-form maintainer notes on cache scope, diagnostic posture, and the post-decl queue's double-dedup design.
Index ¶
- type Builder
- func (s *Builder) AppendPostDecl(decl *scanner.EntityDecl)
- func (s *Builder) Debug(msg string, args ...any)
- func (s *Builder) Diagnostics() []grammar.Diagnostic
- func (s *Builder) MakeRef(decl *scanner.EntityDecl, prop ifaces.SwaggerTypable) error
- func (s *Builder) ParseBlock(cg *ast.CommentGroup) grammar.Block
- func (s *Builder) ParseBlocks(cg *ast.CommentGroup) []grammar.Block
- func (s *Builder) PostDeclarations() []*scanner.EntityDecl
- func (s *Builder) RecordDiagnostic(d grammar.Diagnostic)
- func (s *Builder) Warn(msg string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
Ctx *scanner.ScanCtx
Decl *scanner.EntityDecl
// contains filtered or unexported fields
}
Builder holds the per-decl state shared across every concrete builder via embedding.
See §blockcache, §diagnostics, and §postdecls for the cache scope, accumulator posture, and discovery queue's dedup design.
func New ¶
func New(ctx *scanner.ScanCtx, decl *scanner.EntityDecl) *Builder
New builds a Builder bound to ctx and decl.
The blockCache is pre-allocated empty; logger defaults to slog.Default.
See §quirks-open for the planned configurability.
func (*Builder) AppendPostDecl ¶
func (s *Builder) AppendPostDecl(decl *scanner.EntityDecl)
AppendPostDecl marks decl for post-processing by the spec orchestrator's discovery loop. Idempotent per-Builder: re-appending a decl whose Ident was already seen is a no-op. Nil and Ident-less decls are silently ignored.
Details ¶
See [§postdecls](./README.md#postdecls) — per-Builder dedup index and the second dedup applied at consumption time by spec.Builder.buildDiscovered.
func (*Builder) Diagnostics ¶
func (s *Builder) Diagnostics() []grammar.Diagnostic
Diagnostics returns every grammar.Diagnostic accumulated by this Builder during a Build pass.
Source order is preserved; no deduplication is applied. The slice is owned by the Builder; callers must not mutate it. Returns nil before Build is invoked or when no diagnostics were recorded.
Details ¶
See [§diagnostics](./README.md#diagnostics) — accumulator ordering, dedup posture, and the LSP-evolution caveat (the diagnostic surface is expected to widen once IDE integration matures).
func (*Builder) MakeRef ¶
func (s *Builder) MakeRef(decl *scanner.EntityDecl, prop ifaces.SwaggerTypable) error
MakeRef writes a `$ref: "#/definitions/<name>"` onto prop and registers decl with the discovery loop via AppendPostDecl. The name comes from decl.Names() (the first entry — top-level decls in this codebase have a single name). Returns an error only if oaispec.NewRef rejects the JSON pointer.
Details ¶
See [§makeref](./README.md#makeref) — why the operation lives on the common base and what kinds of cross-cutting refinements that shape enables.
func (*Builder) ParseBlock ¶
func (s *Builder) ParseBlock(cg *ast.CommentGroup) grammar.Block
ParseBlock returns the first Block from Builder.ParseBlocks.
This is the "primary" annotation for callers that don't need multi-annotation visibility (title/description, field-level lookups).
func (*Builder) ParseBlocks ¶
func (s *Builder) ParseBlocks(cg *ast.CommentGroup) []grammar.Block
ParseBlocks returns the cached grammar.Block slice for cg (one entry per annotation), parsing on first access and memoising the result.
Always returns a non-nil slice with at least one Block, so consumers can call [Block.AnnotationKind], [Block.AnnotationArg] / etc. unconditionally on the first element.
Details ¶
See [§blockcache](./README.md#blockcache) — memoisation scope, why ParseAll is preferred over Parse, and the per-Builder (single-goroutine) lifetime that obviates synchronisation.
func (*Builder) PostDeclarations ¶
func (s *Builder) PostDeclarations() []*scanner.EntityDecl
PostDeclarations returns the post-decl queue accumulated by this Builder during a Build pass, in source order.
See [§postdecls](./README.md#postdecls).
func (*Builder) RecordDiagnostic ¶
func (s *Builder) RecordDiagnostic(d grammar.Diagnostic)
RecordDiagnostic accumulates one diagnostic on the Builder and fires the consumer's [Options.OnDiagnostic] callback when wired.
Walker.Diagnostic is bound to this method, so grammar-level warnings flow through the same accumulator as builder-level ones.