cmd

package
v0.0.0-...-e1aea16 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Headers []string

	UserAgent string
)
View Source
var Mode string

Functions

func BuildRequestsFromPaths

func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client, replayClient *http.Client) error

func CheckAndConfigureProxy

func CheckAndConfigureProxy() (client http.Client, replayClient *http.Client, err error)

func CheckSecuritySchemes

func CheckSecuritySchemes(spec map[string]interface{})

func EnforceSingleContentType

func EnforceSingleContentType(newContentType string)

func Execute

func Execute()

Execute runs the root command. It is the single place in the package that terminates the process: command and library code return errors up to here instead of calling os.Exit, which keeps that logic testable and reusable.

func ExtractJSONFromJSSpec

func ExtractJSONFromJSSpec(bodyBytes []byte) ([]byte, bool)

ExtractJSONFromJSSpec scans a Swagger-UI-style JavaScript bundle for an OpenAPI/Swagger document assigned to a top-level var/let/const. If the captured value is itself a wrapper object (swagger-ui-express / swagger-ui bundle config), it unwraps one level via the swaggerDoc/spec/openapi keys. Returns the extracted JSON bytes and true on success, or the original bytes and false on failure.

func ExtractSpecFromJS

func ExtractSpecFromJS(bodyBytes []byte) []byte

func ExtractSpecURLsFromHTML

func ExtractSpecURLsFromHTML(htmlContent, pageURL string) []string

ExtractSpecURLsFromHTML returns the spec/initializer URLs referenced by a Swagger UI page (or swagger-config JSON), resolved against pageURL and deduped.

func GenerateExample

func GenerateExample(node *SchemaNode) interface{}

func GenerateRequests

func GenerateRequests(bodyBytes []byte, client http.Client, replayClient *http.Client) error

func MakeRequest

func MakeRequest(client http.Client, method, target string, timeout int64, reqData io.Reader) ([]byte, string, int, error)

MakeRequest returns the body bytes, body string, and status code. It wraps MakeRequestFull for callers that do not need the Content-Type.

func MakeRequestFull

func MakeRequestFull(client http.Client, method, target string, timeout int64, reqData io.Reader) ([]byte, string, int, string, string, error)

MakeRequestFull also returns the response Content-Type and the User-Agent sent. Taking body and Content-Type from one response avoids a second request per URL.

func PrintSpecInfo

func PrintSpecInfo(spec map[string]interface{})

func ReplayRequest

func ReplayRequest(replayClient *http.Client, method, target string, timeout int64, reqData io.Reader, userAgent string)

userAgent is the one the replayed request carried, so the copy reproduces it.

func ResolveExternalRef

func ResolveExternalRef(ref string, baseDir string) map[string]interface{}

func ResolveRef

func ResolveRef(spec map[string]interface{}, ref string) map[string]interface{}

func ResolveRefWithContext

func ResolveRefWithContext(spec map[string]interface{}, ref string) (map[string]interface{}, map[string]interface{})

ResolveRefWithContext resolves a reference and returns both the resolved schema and the spec it came from

func SafelyUnmarshalSpec

func SafelyUnmarshalSpec(data []byte) (map[string]interface{}, error)

func SetScheme

func SetScheme(swaggerURL string) (scheme string)

func SummarizeOperationSecurity

func SummarizeOperationSecurity(spec map[string]interface{})

SummarizeOperationSecurity prints, to stderr, the effective security requirement of every declared operation. It is computed from the spec alone (no requests), so it runs for automate, endpoints, and prepare alike, and it stays off stdout to keep that stream pipeable.

func TrimHostScheme

func TrimHostScheme(apiTarget, fullUrlHost string) (host string)

TrimHostScheme trims the scheme from the provided URL if the '-T' flag is supplied to sj.

func UnmarshalSpec

func UnmarshalSpec(bodyBytes []byte) (*openapi3.T, error)

func WriteConvertedDefinitionFile

func WriteConvertedDefinitionFile(data []byte)

func XmlFromObject

func XmlFromObject(obj map[string]interface{}) string

Types

type Result

type Result struct {
	Method string `json:"method"`
	Status int    `json:"status"`
	Target string `json:"target"`
	// ContentType names the request body encoding this result came from. It is
	// omitted unless an operation was tested under more than one, so
	// single-variant output is unchanged.
	ContentType string `json:"contentType,omitempty"`
	// Security is the effective security requirement the spec declares for this
	// operation (e.g. "bearerAuth", "public"). Omitted when undeclared.
	Security string `json:"security,omitempty"`
	// MissingAuth is set when the spec marks this operation as requiring auth but
	// it returned a 2xx with no matching credential supplied — a possible broken
	// access control finding.
	MissingAuth bool `json:"missingAuth,omitempty"`
}

type SchemaNode

type SchemaNode struct {
	Type                 string
	Properties           map[string]*SchemaNode
	Items                *SchemaNode
	Required             map[string]bool
	Enum                 []interface{}
	Example              interface{}
	Ref                  string
	OneOf                []*SchemaNode
	AnyOf                []*SchemaNode
	AdditionalProperties *SchemaNode
}

func ExpandSchema

func ExpandSchema(
	spec map[string]interface{},
	schema map[string]interface{},
	visited map[string]bool,
	contextSpec map[string]interface{},
) *SchemaNode

type VerboseResult

type VerboseResult struct {
	Method      string `json:"method"`
	Preview     string `json:"preview"`
	Status      int    `json:"status"`
	Target      string `json:"target"`
	Curl        string `json:"curl"`
	ContentType string `json:"contentType,omitempty"`
	Security    string `json:"security,omitempty"`
	MissingAuth bool   `json:"missingAuth,omitempty"`
}

Jump to

Keyboard shortcuts

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