Documentation
¶
Index ¶
- func CountOperations(data []byte, opts Options) (int64, error)
- func DetectFormatFromContent(data []byte) string
- func DetectFormatFromContentType(contentType string) string
- func IsOpenAPISpec(data []byte) bool
- func LoadSpec(input string) ([]byte, string, error)
- func ParseForServer(data []byte, opts ServerOptions, callback func(*ServerScanRequest)) error
- func ParseOpenAPI(data []byte, opts Options, callback ResultCallback) error
- func ParseSwagger(data []byte, ext string, opts Options, callback ResultCallback) error
- func ParseSwaggerForServer(data []byte, ext string, opts ServerOptions, callback func(*ServerScanRequest)) error
- type Format
- type Options
- type ResultCallback
- type ServerOptions
- type ServerScanRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountOperations ¶
CountOperations counts the number of operations in an OpenAPI spec. If UseSpecServers is true, multiplies by the number of servers.
func DetectFormatFromContent ¶
DetectFormatFromContent detects format by examining content.
func DetectFormatFromContentType ¶
DetectFormatFromContentType detects format from Content-Type header.
func IsOpenAPISpec ¶
IsOpenAPISpec returns true if data looks like an OpenAPI 3.x or Swagger 2.x spec.
func LoadSpec ¶
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 (*Format) Count ¶
Count returns the number of operations in the OpenAPI spec. If UseSpecServers is true, multiplies by number of servers.
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 ¶
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.