Documentation
¶
Overview ¶
Package mockfile reads mock documents and preserves their source while splitting YAML streams.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// Origin identifies the input in problems, including a YAML document number after splitting.
Origin string
// Source is the source identifier recorded on the mock, such as its file path or admin origin.
Source string
// Format selects the JSON or YAML decoder.
Format string
// Dir is where relative body files open. Empty uses the working directory.
Dir string
// Data holds the source document, before schema validation or templating.
Data []byte
// Err retains a read or parse failure from Load for the protocol's build pass.
Err error
}
Document is a mock's source data, or an error Load retains for a server to report with its other build errors.
func Load ¶
Load reads files in their given order and expands their YAML documents. A failed file contributes one Document with Err set, so servers can report every bad file while keeping their existing all-or-nothing build path.
func Read ¶
Read reads a JSON or YAML mock file. missingHint optionally explains how to find a missing file. Relative body files start at the returned Dir. Failures are config.Error values with scope mock.
func (Document) Builder ¶
func (doc Document) Builder[M, A any](multiHint string, build func(Document, A) (M, error)) builder[M, A]
Builder defers building this single document until Build supplies the server.
func (Document) Decode ¶
func (doc Document) Decode[T any](schema *config.Schema[T], dst *T, check func(string, []config.Problem) []config.Problem) error
Decode loads the document into dst, then adds check's cross-field problems when parsing succeeded. It preserves schema problems and their order; a retained file error passes through before schema loading.