doc

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderHeading

func RenderHeading(tmpl, blockName string) string

Render produces a heading string from a template and block name. For {Block} templates, inserts the name directly. For {Path} templates, inserts the dot-notation path directly (the caller is expected to pass a path-shaped name). For {Title} templates, converts snake_case to Title Case. {Parent} is left as-is (caller must substitute if needed).

Types

type ChildHeading

type ChildHeading struct {
	Level       int
	Text        string
	Line        int // 1-based line number of the heading in source
	StartOffset int // byte offset of the heading's first byte in source
}

ChildHeading records a heading nested inside a section.

type DocAttribute

type DocAttribute struct {
	Name        string
	Required    bool
	Optional    bool
	ReadOnly    bool
	Deprecated  bool
	Description string
	Line        int // 1-based line number in the source file
}

DocAttribute represents a single documented attribute.

type DocBlock

type DocBlock struct {
	Name                string
	Heading             string
	Attributes          []DocAttribute
	MalformedAttributes []MalformedAttr // attributes found but with formatting issues
	SplitByLabel        bool            // true if the doc explicitly separates required/optional with distinct bylines
}

DocBlock represents a documented block section.

type Document

type Document struct {
	ResourceName    string
	ArgumentBlocks  map[string]*DocBlock
	AttributeBlocks map[string]*DocBlock
	Sections        *Sections
	// contains filtered or unexported fields
}

Document represents a parsed documentation file.

func Parse

func Parse(source []byte, name string) (*Document, error)

Parse parses markdown source (accepts all heading styles).

func ParseFile

func ParseFile(path string) (*Document, error)

ParseFile reads and parses a markdown documentation file (accepts all heading styles).

func ParseFileWithTemplates

func ParseFileWithTemplates(path string, templates HeadingTemplates) (*Document, error)

ParseFileWithTemplates reads and parses with specific heading templates.

func ParseWithTemplates

func ParseWithTemplates(source []byte, name string, templates HeadingTemplates) (*Document, error)

ParseWithTemplates parses markdown source with specific heading templates.

func (*Document) Blocks

func (d *Document) Blocks() map[string]*DocBlock

Blocks returns a merged view of argument + attribute blocks. The returned map is independent — it does not mutate the original blocks.

func (*Document) Source

func (d *Document) Source() []byte

Source returns the raw markdown source bytes.

type HeadingTemplates

type HeadingTemplates []string

HeadingTemplates defines patterns for recognizing block headings. Use {Block} for a snake_case block name placeholder. Use {Title} for a title-case name placeholder (converted to snake_case).

func DefaultHeadingTemplates

func DefaultHeadingTemplates() HeadingTemplates

DefaultHeadingTemplates accepts common formats, including the tfplugindocs "Nested Schema for `<path>`" form and the dot-notation `<path>` Block / `<path>` forms that disambiguate blocks whose leaf names repeat under multiple parents.

func (HeadingTemplates) Match

func (t HeadingTemplates) Match(heading string) string

Match tries each template against a heading and returns the extracted block name, or "".

func (HeadingTemplates) MatchAll

func (t HeadingTemplates) MatchAll(heading string) []string

MatchAll returns all block names from a heading. Combined headings like "`publish_auth_mode` and `subscribe_auth_mode`" return both names.

MatchAll is only meaningful for headings that the doc structure permits in the Argument Reference or Attribute Reference sections. The parser guards the call site so it never sees Example Usage subheadings.

type MalformedAttr

type MalformedAttr struct {
	Name string
	Line int
}

MalformedAttr records an attribute name with a formatting issue and its location.

type NestedRef added in v0.14.0

type NestedRef struct {
	Parent      string // dot-separated path with array indexers stripped
	Attribute   string // leaf attribute name
	Description string
	Required    bool
	Optional    bool
	ReadOnly    bool
}

NestedRef represents a dot-notation reference to a nested attribute, e.g. `network[*].private_ip`, `tags[0].key`, or `analyzer_configuration.unused_access_configuration.unused_access_age`. These appear in the root Argument Reference / Attribute Reference sections as a convenience shorthand when the author doesn't want to introduce separate nested block headings, and in tfplugindocs-style schemas where deeply-nested attribute paths are documented inline.

type Section

type Section struct {
	Heading          *ast.Heading
	Text             string
	FencedCodeBlocks []*ast.FencedCodeBlock
	Paragraphs       []*ast.Paragraph

	// ChildHeadings are headings at level > the section's own level that
	// appear before the next same-or-lower-level heading. Used by rules
	// that check for required sub-sections (e.g. "### Basic Usage" inside
	// "## Example Usage").
	ChildHeadings []ChildHeading

	// ListItems are the top-level list items found in this section. Used by
	// rules that validate structured lists (e.g. timeout actions).
	ListItems []SectionListItem

	// StartOffset and EndOffset are byte offsets into the source marking the
	// section's extent (from the heading's first byte to the byte before the
	// next same-or-lower-level heading, or EOF). Rules that need raw source
	// patterns (e.g. import block format) slice source[StartOffset:EndOffset].
	StartOffset int
	EndOffset   int
}

Section captures one top-level section of a provider documentation file: a heading and the content that follows it up to the next heading of the same or lower level. Only the pieces rules actually read — the heading node, its text for convenience, the fenced code blocks, and the paragraphs — are tracked. List nodes are deliberately excluded because ArgumentBlocks and AttributeBlocks already cover the only sections where lists matter.

type SectionListItem

type SectionListItem struct {
	Name  string
	Value string
	Line  int
}

SectionListItem records a single top-level list item in a section. Name is the backtick-wrapped identifier (e.g. "create") and Value is the remainder after the " - " separator (e.g. "(Default `60m`)").

type Sections

type Sections struct {
	Title      *Section // level-1 heading (# Resource: foo)
	Signature  *Section // ## Signature (functions)
	Example    *Section // ## Example Usage
	Arguments  *Section // ## Argument Reference
	Attributes *Section // ## Attribute Reference
	Timeouts   *Section // ## Timeouts
	Import     *Section // ## Import

	// UnknownHeadings records every level-2 heading that did not map to one
	// of the recognized sections above. The parser captures these so the
	// section_presence rule can flag stray sections like ## My wild heading.
	// Each entry's Level is always 2; Text is the raw heading text.
	UnknownHeadings []ChildHeading
}

Sections is the typed view of the top-level sections of a doc file. Any field is nil when the corresponding section is absent — for example a data source will typically have Import == nil, a function will have Signature set but no Import or Timeouts.

The struct has fixed fields (rather than a map) so rules get type-safe access and new categories are an explicit code change. Add fields when a new section genuinely needs rule-level support; don't use this as a general-purpose bag.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL