Documentation
¶
Overview ¶
Package godoclink rewrites godoc-specific syntax that reads as noise when a Go doc comment is carried into a Swagger title / description (the Options.CleanGoDoc feature).
Two transforms apply to godoc-derived prose:
- resolution-free cleanup: reference-style link definition lines (`[text]: url`) are dropped; godoc doc-link spans (`[Widget]`, `[pkg.Type]`, `[Order.Field]`) have their brackets removed and the (leaf) identifier humanized via the swag name mangler — e.g. `[CustName]` → "cust name"; the first identifier of the prose is restored to sentence case;
- idiom recomposition: when a Resolver maps a doc-link (or the leading godoc-convention self-name) to an emitted schema, the span is replaced by a [marker] carrying that schema's fully-qualified definition key. Markers are resolved to the schema's final exposed name by SubstituteMarkers, run after the spec builder has reduced definition names. This two-step dance is needed because the final name is only known at the very end of the build, whereas which prose is godoc-derived is only known here, at the consumption seam.
With a nil Options.Resolver (and nil Self), only the resolution-free cleanup runs and no marker is produced.
The recognizer regexes are adapted from the battle-tested github.com/fredbi/go-fred-mcp/pkg/doc-filters/godoc-filter; the key difference is that this package *rewrites* the prose whereas that tool *redacts* (length-preserving blanking) for masking.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
Clean applies godoc filtering to text.
It is the caller's responsibility to apply Clean ONLY to godoc-derived prose — never to author-written swagger:title / swagger:description override text. Clean never mutates o.
func HasMarkers ¶
HasMarkers reports whether s contains any godoclink marker — a cheap guard so callers can skip the substitution walk for marker-free prose.
func SubstituteMarkers ¶
SubstituteMarkers rewrites every marker in text to its final exposed name. finalName maps a definition key to the name it is ultimately emitted under, returning ok=false when the key is not an emitted definition (pruned or unresolved); in that case the marker collapses to its humanized fallback.
A resolved marker yields finalName+suffix. The sentence-initial bit, when set, upper-cases the first rune of the result. No marker ever survives this pass.
Types ¶
type Options ¶
type Options struct {
// Mangler humanizes leaf identifiers (and marker fallbacks).
//
// Required.
Mangler *mangling.NameMangler
// Resolver, when non-nil, recomposes resolvable doc-links into markers; nil selects
// resolution-free cleanup only.
Resolver Resolver
// Self, when non-nil, enables leading self-name recomposition.
//
// It has effect only together with a non-nil Resolver.
Self *SelfRef
}
Options configures Clean.
type Resolution ¶
Resolution is the outcome of resolving a doc-link reference to an emitted schema.
DefKey is the referenced type's fully-qualified definition key (whose final exposed name is substituted later); Suffix is the already-exposed field chain for a dotted member reference (e.g. ".customer_name"), or "" for a bare type reference.
type Resolver ¶
type Resolver func(ref string) (Resolution, bool)
Resolver maps a doc-link reference — the bracket content with any leading `*` stripped, e.g. "Order.CustName" or "pkg.Type" — to a Resolution.
It returns ok=false when the reference does not resolve to an emitted schema, in which case the caller humanizes the leaf identifier instead.