generator

package
v2.1.93 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDefaultContexts

func LoadDefaultContexts() []map[string]map[string]any

LoadDefaultContexts loads the built-in replacement contexts (common, fake, words). This allows standalone usage without an api.Router.

func LoadServiceContext

func LoadServiceContext(serviceCtx []byte, defaultContexts []map[string]map[string]any) []map[string]any

LoadServiceContext loads the service context and combines it with the default contexts. It returns a flattened array of context maps in a specific order:

  • [0]: service - The service-specific context loaded from serviceCtx YAML
  • [1]: common - Common context with patterns like _id$, _email$, etc. (from resources/contexts/common.yml)
  • [2]: fake - Fake data generators for testing (from resources/contexts/fake.yml)
  • [3]: words - Common words for realistic-looking data (from resources/contexts/words.yml)

The map keys ("service", "common", "fake", "words") correspond to context namespaces that are loaded from embedded YAML files in the resources/contexts directory. These namespaces are used during the Load() call to organize and resolve context data, but are discarded in the returned array since only the values are needed for replacement.

Types

type Generate

type Generate interface {
	Request(req *api.GenerateRequest, op *schema.Operation, ctxData map[string]any) json.RawMessage
	Response(respSchema *schema.ResponseSchema, ctxData map[string]any) schema.ResponseData
	Error(errSchema *schema.Schema, errPath, error string) []byte
}

type ResponseGenerator

type ResponseGenerator struct {
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(orderedCtx []map[string]any, defaultContexts []map[string]map[string]any) (*ResponseGenerator, error)

func (*ResponseGenerator) Error

func (g *ResponseGenerator) Error(errSchema *schema.Schema, errPath, error string) []byte

func (*ResponseGenerator) Request

func (g *ResponseGenerator) Request(req *api.GenerateRequest, op *schema.Operation, ctxData map[string]any) json.RawMessage

func (*ResponseGenerator) Response

func (g *ResponseGenerator) Response(respSchema *schema.ResponseSchema, ctxData map[string]any) schema.ResponseData

Jump to

Keyboard shortcuts

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