Documentation
¶
Index ¶
- type Factory
- func (f *Factory) FindOperation(path, method string) *schema.Operation
- func (f *Factory) MatchPath(requestPath, method string) (string, bool)
- func (f *Factory) Operations() []typedef.RouteInfo
- func (f *Factory) Request(path, method string, ctx map[string]any) (schema.GeneratedRequest, error)
- func (f *Factory) RequestBody(path, method string, ctx map[string]any) (json.RawMessage, error)
- func (f *Factory) Response(path, method string, ctx map[string]any) (schema.ResponseData, error)
- func (f *Factory) ResponseBody(path, method string, ctx map[string]any) (json.RawMessage, error)
- func (f *Factory) ResponseBodyFromRequest(r *http.Request, ctx map[string]any) (json.RawMessage, error)
- func (f *Factory) ResponseFromRequest(r *http.Request, ctx map[string]any) (schema.ResponseData, error)
- type FactoryOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory generates mock requests and responses based on an OpenAPI spec. It wraps the registry and generator for convenient programmatic use.
func NewFactory ¶
func NewFactory(specBytes []byte, opts ...FactoryOption) (*Factory, error)
NewFactory creates a Factory from raw OpenAPI spec bytes. Default replacement contexts (common, fake, words) are loaded automatically.
func (*Factory) FindOperation ¶ added in v2.1.72
FindOperation returns the parsed operation for the given spec path and method.
func (*Factory) MatchPath ¶ added in v2.1.72
MatchPath resolves a concrete request path (e.g., /users/42) to the corresponding OpenAPI spec path pattern (e.g., /users/{id}). Returns the spec path and true if a match is found.
func (*Factory) Operations ¶
Operations returns route info for all available operations.
func (*Factory) Request ¶
Request generates a mock request for the given spec path and method. Returns a GeneratedRequest with path (param values filled), contentType, headers, and body. ctx is an optional replacement context for controlling generated values.
func (*Factory) RequestBody ¶
RequestBody generates just the request body bytes for the given spec path and method. ctx is an optional replacement context for controlling generated values.
func (*Factory) Response ¶
Response generates a mock response for the given spec path and method. path should be the OpenAPI path pattern (e.g., "/users/{id}"). ctx is an optional replacement context for controlling generated values.
func (*Factory) ResponseBody ¶
ResponseBody generates just the response body bytes for the given spec path and method. ctx is an optional replacement context for controlling generated values.
func (*Factory) ResponseBodyFromRequest ¶
func (f *Factory) ResponseBodyFromRequest(r *http.Request, ctx map[string]any) (json.RawMessage, error)
ResponseBodyFromRequest generates response body bytes matching the given HTTP request. It automatically matches the request path (e.g., /users/42) to the corresponding spec path pattern (e.g., /users/{id}). ctx is an optional replacement context for controlling generated values.
func (*Factory) ResponseFromRequest ¶
func (f *Factory) ResponseFromRequest(r *http.Request, ctx map[string]any) (schema.ResponseData, error)
ResponseFromRequest generates a mock response matching the given HTTP request. It automatically matches the request path (e.g., /users/42) to the corresponding spec path pattern (e.g., /users/{id}) and generates a response. ctx is an optional replacement context for controlling generated values.
type FactoryOption ¶
type FactoryOption func(*factoryConfig)
FactoryOption configures a Factory.
func WithCodegenConfig ¶
func WithCodegenConfig(cfg codegen.Configuration) FactoryOption
WithCodegenConfig sets the codegen configuration used for spec parsing. When not provided, the default codegen configuration is used.
func WithServiceContext ¶
func WithServiceContext(contextYAML []byte) FactoryOption
WithServiceContext sets a service-specific context YAML for value replacements.
func WithSpecOptions ¶
func WithSpecOptions(opts *config.SpecOptions) FactoryOption
WithSpecOptions sets OpenAPI spec parsing options.