openapi

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package openapi provides OpenAPI specification parsing functionality. It extracts endpoint definitions from OpenAPI 3.0 specs for use in load testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsJSONContentType

func IsJSONContentType(contentType string) bool

IsJSONContentType reports whether a media type is JSON-compatible.

func ResolvePath

func ResolvePath(path string, params []Parameter, values map[string]string) string

ResolvePath replaces path parameters with provided values. Parameters not found in the values map are replaced with placeholder values based on their type (e.g., "1" for integers, "test" for strings).

EXAMPLE:

path: "/users/{id}/posts/{postId}"
values: map[string]string{"id": "123"}
result: "/users/123/posts/1" (postId gets default integer placeholder)

Types

type Endpoint

type Endpoint struct {
	Method      string      // HTTP method (GET, POST, PUT, DELETE, etc.)
	Path        string      // URL path pattern (e.g., "/users/{id}")
	OperationID string      // Unique operation identifier from the spec
	Parameters  []Parameter // Path, query, and header parameters
	ContentType string      // JSON request content type when payload generation succeeds
	Body        []byte      // Generated JSON request payload when requestBody synthesis succeeds
	HasBody     bool        // Whether the endpoint expects a request body
	Tags        []string    // Grouping tags from the spec
}

Endpoint represents a single API endpoint extracted from the OpenAPI spec. It contains all necessary information to construct HTTP requests during load testing.

type Parameter

type Parameter struct {
	Name     string // Parameter name
	In       string // Location: "path", "query", "header", "cookie"
	Required bool   // Whether the parameter is required
	Type     string // Data type (string, integer, etc.)
	Example  any    // Example value from the spec, if available
}

Parameter represents a single parameter definition from the OpenAPI spec.

type Parser

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

Parser handles OpenAPI specification parsing.

func NewParser

func NewParser() *Parser

NewParser creates a new OpenAPI parser with default configuration. The parser is configured to resolve external references if encountered.

func (*Parser) ParseFile

func (p *Parser) ParseFile(ctx context.Context, path string) ([]Endpoint, error)

ParseFile reads and parses an OpenAPI specification from the given file path. It validates the spec structure and extracts all endpoint definitions.

Jump to

Keyboard shortcuts

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