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 ¶
- func ScanInLocation(text string) (value string, valid bool, invalid string)
- type Builder
- func (s *Builder) AppendPostDecl(decl *scanner.EntityDecl)
- 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) ReadEmbedInheritance(doc *ast.CommentGroup, current EmbedInheritance) EmbedInheritance
- func (s *Builder) RecordDiagnostic(d grammar.Diagnostic)
- func (s *Builder) ResetPostDeclarations()
- func (s *Builder) WarnStrippedPathRegex(pos token.Pos, params []string)
- type EmbedInheritance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanInLocation ¶ added in v0.35.0
ScanInLocation finds the first `in: X` line in text and returns the canonical OAS v2 form of X (when recognised, case-insensitive via grammar.NormalizeIn) or the raw candidate (when present but out-of-vocabulary). The `form` alias is NOT accepted here — it is contained to the routes inline-param path.
Shared by the parameters and responses field-signal scanners and by Builder.ReadEmbedInheritance; `in:` is line-scanned rather than read as a grammar Property because grammar attaches pre-annotation lines to the following annotation's prose, not its property list.
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.
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) ReadEmbedInheritance ¶ added in v0.35.0
func (s *Builder) ReadEmbedInheritance(doc *ast.CommentGroup, current EmbedInheritance) EmbedInheritance
ReadEmbedInheritance merges the `in:`/`required:` directives on an embedded field's doc comment into current, returning the context to pass down to the fields that embed promotes. The embed's own directives override the inherited ones; absent directives carry current through unchanged.
doc is the embed field's *ast.CommentGroup (nil → current unchanged).
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.
func (*Builder) ResetPostDeclarations ¶ added in v0.35.0
func (s *Builder) ResetPostDeclarations()
ResetPostDeclarations drops every decl this Builder enqueued during the current Build pass. Used by the SimpleSchema catch-at-exit validator: when a non-body parameter / response-header element dissolves an illegal $ref, the decl that MakeRef discovered for that ref is a byproduct of the now-removed reference and would otherwise linger as an orphan definition (go-swagger#1088). A single-type Build renders exactly one target, so every queued decl is reachable only through it; clearing the whole queue is correct. A decl genuinely referenced elsewhere is re-discovered by that other site's Builder and deduplicated by the orchestrator.
Details ¶
See [§postdecls](./README.md#postdecls).
func (*Builder) WarnStrippedPathRegex ¶ added in v0.35.0
WarnStrippedPathRegex records a warning that one or more inline regex path-parameter constraints (`{id:[0-9]+}`) were stripped to the bare `{id}` template form. OpenAPI 2.0 path templating follows RFC 6570 URI Template Level-1 expansion (simple `{name}` substitution) only — it cannot express regex/operator constraints — so the route is still emitted, with the constraint dropped. No-op when params is empty. Shared by the routes and operations builders.
type EmbedInheritance ¶ added in v0.35.0
EmbedInheritance carries the doc-comment directives an embedded (anonymous) struct field passes down to the members it promotes: the `in:` location and the `required:` flag. It is the shared kernel of the "annotations on an embed apply to its promoted members" rule, used by the schema, parameters, and responses builders so the behaviour is identical everywhere. See go-swagger#2701.
Semantics:
- A member's own `in:`/`required:` always wins; the inherited value is a fallback the member consults only when it sets nothing itself.
- An embed that omits a directive leaves the corresponding inherited value unchanged, so nesting accumulates (an inner embed without its own `in:` keeps the outer one).
- `in:` is meaningful only to the parameters and responses builders (the schema builder has no location concept); `required:` is meaningful to the parameters and schema builders (OAS2 response headers carry no `required`).