oapi

package
v0.0.0-...-ac012d0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MockServerBaseURL = "MOCK_SERVER_BASE_URL"

MockServerBaseURL constant

Variables

This section is empty.

Functions

func BuildRouter

func BuildRouter(doc *openapi3.T) (routers.Router, error)

BuildRouter builds a legacy kin-openapi router from a parsed OpenAPI document. The router is used with openapi3filter.FindRoute for response schema validation.

func MarshalScenarioToOpenAPI

func MarshalScenarioToOpenAPI(title string, version string, scenarios ...*types.APIScenario) ([]byte, error)

MarshalScenarioToOpenAPI converts open-api specs into json

func ScenarioToOpenAPI

func ScenarioToOpenAPI(title string, version string, scenarios ...*types.APIScenario) *openapi3.T

ScenarioToOpenAPI convert scenarios to open-api specs

Types

type APISpec

type APISpec struct {
	Title               string
	ID                  string
	Summary             string
	Description         string
	Path                string
	Method              types.MethodType
	Tags                []string
	Deprecated          bool
	ExternalDocsURL     string
	RequestBodyRequired bool
	SecuritySchemes     openapi3.SecuritySchemes
	Request             Request
	Response            Response
}

APISpec structure

func Parse

func Parse(ctx context.Context, config *types.Configuration, data []byte,
	dataTemplate fuzz.DataTemplateRequest) (specs []*APISpec, updated []byte, doc *openapi3.T, err error)

Parse parses Open-API and generates api scenarios. Returns specs, the re-serialized spec bytes, the parsed openapi3.T document, and any error.

func ParseAPISpec

func ParseAPISpec(
	title string,
	method types.MethodType,
	path string,
	op *openapi3.Operation,
	dataTemplate fuzz.DataTemplateRequest) (specs []*APISpec)

ParseAPISpec converts open-api operation to API specs

func ParseAPISpecWithDiscriminatorVariants

func ParseAPISpecWithDiscriminatorVariants(
	title string,
	method types.MethodType,
	path string,
	op *openapi3.Operation,
	dataTemplate fuzz.DataTemplateRequest,
) []*APISpec

ParseAPISpecWithDiscriminatorVariants is like ParseAPISpec but generates one *APISpec per discriminator variant when a response body schema contains oneOf/anyOf. For schemas without discriminator variants, behavior is identical to ParseAPISpec.

func (*APISpec) BuildMockScenario

func (api *APISpec) BuildMockScenario(dataTemplate fuzz.DataTemplateRequest) (*types.APIScenario, error)

BuildMockScenario builds api scenario from open-API spec

type DiscriminatorVariant

type DiscriminatorVariant struct {
	Name   string
	Schema *openapi3.Schema
}

DiscriminatorVariant holds a named variant schema from a oneOf/anyOf discriminator.

func DiscriminatorVariants

func DiscriminatorVariants(schema *openapi3.Schema) []DiscriminatorVariant

DiscriminatorVariants returns named variants for a oneOf/anyOf schema. Uses discriminator.mapping keys when present; otherwise derives names from $ref paths or falls back to "variant0", "variant1", etc. Returns nil when the schema has no oneOf/anyOf branches.

type Property

type Property struct {
	Name         string
	Title        string // schema title
	Description  string
	Type         string
	SubType      string
	Enum         []string
	Const        string // single allowed value (highest priority in Value())
	Default      string // default value used when no other value is generated
	Example      string // example value from OpenAPI spec
	Min          float64
	Max          float64
	ExclusiveMin bool    // minimum bound is exclusive (OAI 3.0)
	ExclusiveMax bool    // maximum bound is exclusive (OAI 3.0)
	MultipleOf   float64 // value must be a multiple of this (0 = no constraint)
	UniqueItems  bool    // array items must be unique
	MinProps     uint64  // minimum number of object properties
	MaxProps     uint64  // maximum number of object properties (0 = no limit)
	In           string
	Pattern      string
	Format       string
	Required     bool
	Deprecated   bool
	Nullable     bool
	ReadOnly     bool
	WriteOnly    bool
	Style        string // parameter serialization style (form, simple, matrix, etc.)
	Explode      bool   // expand array/object parameters into individual values
	Children     []Property
	// contains filtered or unexported fields
}

Property structure

func (*Property) GetName

func (prop *Property) GetName() string

func (*Property) String

func (prop *Property) String() string

func (*Property) Value

func (prop *Property) Value(dataTemplate fuzz.DataTemplateRequest) any

Value of the property

type Request

type Request struct {
	PathParams  []Property
	QueryParams []Property
	Headers     []Property
	Body        []Property
}

Request Body

type Response

type Response struct {
	ContentType string
	StatusCode  int
	Headers     []Property
	Body        []Property
}

Response Body

Jump to

Keyboard shortcuts

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