server

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "master"

Version set in Stripe-Mock-Version response header This is set to the actual version by GoReleaser (using `-ldflags "-X ..."`) as it's run. Versions built from source will always show master.

Functions

func LoadFixtures

func LoadFixtures(embeddedFixtures []byte, fixturesPath string) (*spec.Fixtures, error)

LoadFixtures load fixtures from a JSON file

If path is empty, fixtures are loaded from internal embedded assets.

func LoadSpec

func LoadSpec(embeddedSpec []byte, specPath string) (*spec.Spec, error)

LoadSpec loads OpenAPI spec from a JSON file

If path is empty, the spec is loaded from internal embedded assets.

Types

type DataGenerator

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

DataGenerator generates fixture response data based off a response schema, a set of definitions, and a fixture store.

func (*DataGenerator) Generate

func (g *DataGenerator) Generate(params *GenerateParams) (interface{}, error)

Generate generates a fixture response.

type DoubleSlashFixHandler

type DoubleSlashFixHandler struct {
	Mux http.Handler
}

DoubleSlashFixHandler is a specialized handler that wraps an HTTP mux and deduplicates any doubled slashes that are included in an incoming path. So `//v1/charges` would become `/v1/charges`. This works around the standard Go behavior, which is to redirect the request with a 301 before it reaches the underlying handler.

The reason we deduplicate is that in some API libraries occasionally generate paths with double slashes, and the real Stripe API responds to these requests normally, so stripe-mock emulates that behavior.

func (*DoubleSlashFixHandler) ServeHTTP

ServeHTTP serves an HTTP request.

type ExpansionLevel

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

ExpansionLevel represents expansions on a single "level" of resource. It may have subexpansions that are meant to take effect on resources that are nested below it (on other levels).

type GenerateParams

type GenerateParams struct {
	// Expansions are the requested expansions for the current level of generation.
	//
	// nil if no expansions were requested, or we've recursed to a level where
	// none of the original expansions applied.
	Expansions *ExpansionLevel

	// PathParams, if set, is a collection that contains values for parameters
	// that were extracted from a request path. This is useful so that we can
	// reflect those values into responses for a more realistic effect.
	//
	// nil if there were no values extracted from the path.
	//
	// The value of this field is considered in a post-processing step for the
	// generator. It's not used in the generator at all.
	PathParams *PathParamsMap

	// RequestData is a collection of decoded data that was included as part of
	// the request's payload.
	//
	// It's used to find opportunities to reflect information included with a
	// request into the response to make responses look more accurate than
	// they'd otherwise be if they'd been generated from fixtures alone..
	RequestData map[string]interface{}

	// RequestMethod is the HTTP method of the URL being requested which we're
	// generating data for. It's used to decide between returning a deleted and
	// non-deleted schema in some cases.
	//
	// The value of this field is expected to stay stable across all levels of
	// recursion.
	RequestMethod string

	// RequestPath is the path of the URL being requested which we're
	// generating data for. It's used to populate the url property of any
	// nested lists that we generate.
	//
	// The value of this field is expected to stay stable across all levels of
	// recursion.
	RequestPath string

	// Schema representing the object that we're trying to generate.
	//
	// The value of this field will change as Generate recurses to the target
	// schema at that level of recursion.
	//
	// This field is required.
	Schema *spec.Schema
	// contains filtered or unexported fields
}

GenerateParams is a parameters structure that's used to invoke Generate and its associated methods.

This structure exists to avoid runaway paramete inflation for the Generate function, so that we can document individual parameters in a more organized way, and because it can conveniently encapsulate some unexported fields that Generate uses to track its progress.

type PathParamsMap

type PathParamsMap struct {
	// PrimaryID contains a value for a primary ID extracted from a request
	// path. A "primary" object is the one being enacted on and which will be
	// directly returned with the API's response.
	//
	// Note that not all endpoints have a primary ID, and in those cases this
	// value will be nil. Examples of endpoints without a primary ID are
	// "create" and "list" methods.
	PrimaryID *string

	// SecondaryIDs contains a collection of "secondary IDs" (i.e., not the
	// primary ID) extracted from the request path.
	SecondaryIDs []*PathParamsSecondaryID
	// contains filtered or unexported fields
}

PathParamsMap holds a collection of parameter that values that have been extracted from the path of a request. This is useful to hand off to the data generator so that it can use these IDs while generating results.

type PathParamsSecondaryID

type PathParamsSecondaryID struct {
	// ID is the value of the parameter extracted from the request path.
	ID string

	// Name is the name of the parameter according to the enclosing `{}` in the
	// OpenAPI specification.
	//
	// For example, it might read `fee` if extracted from:
	//
	//     /v1/application_fees/{fee}/refunds
	//
	Name string
	// contains filtered or unexported fields
}

PathParamsSecondaryID holds the name and value for a "secondary ID" (i.e., one that is not the primary ID) found in a request path.

type ResponseError

type ResponseError struct {
	ErrorInfo struct {
		Message string `json:"message"`
		Type    string `json:"type"`
	} `json:"error"`
}

ResponseError is a JSON-serializable structure representing an error returned from Stripe's API.

type StubServer

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

StubServer handles incoming HTTP requests and responds to them appropriately based off the set of OpenAPI routes that it's been configured with.

func NewStubServer

func NewStubServer(fixtures *spec.Fixtures, spec *spec.Spec, strictVersionCheck, verbose bool) (*StubServer, error)

NewStubServer creates a new instance of StubServer

func (*StubServer) HandleRequest

func (s *StubServer) HandleRequest(w http.ResponseWriter, r *http.Request)

HandleRequest handes an HTTP request directed at the API stub.

Jump to

Keyboard shortcuts

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