openapi

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountOperations

func CountOperations(data []byte, opts Options) (int64, error)

CountOperations counts the number of operations in an OpenAPI spec. If UseSpecServers is true, multiplies by the number of servers.

func DetectFormatFromContent

func DetectFormatFromContent(data []byte) string

DetectFormatFromContent detects format by examining content.

func DetectFormatFromContentType

func DetectFormatFromContentType(contentType string) string

DetectFormatFromContentType detects format from Content-Type header.

func IsOpenAPISpec

func IsOpenAPISpec(data []byte) bool

IsOpenAPISpec returns true if data looks like an OpenAPI 3.x or Swagger 2.x spec.

func LoadSpec

func LoadSpec(input string) ([]byte, string, error)

LoadSpec loads an OpenAPI/Swagger spec from a file path or URL. Returns the content bytes and detected format extension (.json, .yaml, .yml).

func ParseForServer

func ParseForServer(data []byte, opts ServerOptions, callback func(*ServerScanRequest)) error

ParseForServer parses an OpenAPI spec and calls callback with ServerScanRequest.

func ParseOpenAPI

func ParseOpenAPI(data []byte, opts Options, callback ResultCallback) error

ParseOpenAPI parses an OpenAPI 3.0 spec and generates HttpRequestResponse.

func ParseSwagger

func ParseSwagger(data []byte, ext string, opts Options, callback ResultCallback) error

ParseSwagger parses a Swagger 2.0 spec, converts it to OpenAPI 3.0, and generates HttpRequestResponse. It auto-detects wrapper structures (swaggerDoc) and spec version (OpenAPI 3.x vs Swagger 2.x).

func ParseSwaggerForServer

func ParseSwaggerForServer(data []byte, ext string, opts ServerOptions, callback func(*ServerScanRequest)) error

ParseSwaggerForServer parses a Swagger spec and calls callback with ServerScanRequest.

Types

type Format

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

Format implements formats.Format interface for OpenAPI/Swagger specs.

func New

func New() *Format

New creates a new OpenAPI Format.

func (*Format) Count

func (f *Format) Count(input string) (int64, error)

Count returns the number of operations in the OpenAPI spec. If UseSpecServers is true, multiplies by number of servers.

func (*Format) Name

func (f *Format) Name() string

Name returns the name of the format.

func (*Format) Parse

func (f *Format) Parse(input string, callback formats.ParseReqRespCallback) error

Parse parses an OpenAPI/Swagger spec file and calls callback for each request.

func (*Format) SetOpenAPIOptions

func (f *Format) SetOpenAPIOptions(opts Options)

SetOpenAPIOptions sets OpenAPI-specific options.

func (*Format) SetOptions

func (f *Format) SetOptions(options formats.InputFormatOptions)

SetOptions sets the generic format options.

type Options

type Options struct {
	// BaseURL overrides servers in spec (e.g., https://api.example.com)
	BaseURL string

	// UseSpecServers allows using servers defined in spec when BaseURL is not provided
	UseSpecServers bool

	// PreserveSpecServerPath, when BaseURL is set, keeps the scheme/host from BaseURL
	// (so the in-scope target host is enforced) but uses the path prefix declared by
	// the spec's own servers / Swagger basePath instead of discarding it. Without this,
	// a spec served at host/openapi.json that declares servers:[{url:"https://x/api/v3"}]
	// would generate requests to host/<op> (404 noise) instead of host/api/v3/<op>.
	// Used by spec auto-ingestion (discovery + api-spec-ingest); the explicit
	// `import`/`scan -i` paths keep the full-override behaviour.
	PreserveSpecServerPath bool

	// Headers are custom headers to add to all requests
	Headers map[string]string

	// Variables are parameter values (e.g., api_key=abc123)
	Variables map[string]string

	// DefaultFallbackValue is used for required params without examples
	DefaultFallbackValue string

	// RequiredOnly only uses required fields when generating requests
	RequiredOnly bool

	// SkipFormatValidation is used to skip format validation
	SkipFormatValidation bool

	// FieldTypeDefaults provides configurable default values per field type.
	// Used when OpenAPI specs lack examples. Keys are type names (e.g. "email", "uuid").
	FieldTypeDefaults map[string][]string
}

Options contains options for parsing OpenAPI specs.

type ResultCallback

type ResultCallback func(*httpmsg.HttpRequestResponse) bool

ResultCallback is called for each generated HttpRequestResponse.

type ServerOptions

type ServerOptions struct {
	Options

	// EnableModules is the list of modules to enable for scan requests
	EnableModules []string

	// WebhookURL is the webhook URL for results
	WebhookURL string
}

ServerOptions extends Options with server-mode specific fields.

type ServerScanRequest

type ServerScanRequest struct {
	URL           string
	RawRequest    string
	EnableModules []string
	WebhookURL    string
}

ServerScanRequest is a lightweight scan request type used by the adapter to avoid importing pkg/server/api (which would create a cycle).

Jump to

Keyboard shortcuts

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