Documentation
¶
Index ¶
- Constants
- func AreSchemasEqual(a, b Schema) bool
- func GenerateOpenAPISpec(transactions []proxy.APITransaction, ...) ([]byte, error)
- func GetPathParameters(path, template string) map[string]string
- type APIDefinition
- type AuthDetector
- type AuthScheme
- type Components
- type Encoding
- type Example
- type Header
- type MediaType
- type Operation
- type Parameter
- type PathPatternDetector
- type RequestBody
- type Response
- type Schema
- type SchemaMerger
- type TypeInferrer
Constants ¶
const OpenAPIVersion = "3.0.3"
OpenAPIVersion is the OpenAPI version used in generated specs
Variables ¶
This section is empty.
Functions ¶
func AreSchemasEqual ¶
AreSchemasEqual checks if two schemas are semantically equivalent
func GenerateOpenAPISpec ¶
func GenerateOpenAPISpec(transactions []proxy.APITransaction, title, description, version, basePath string) ([]byte, error)
Generate OpenAPI spec from API transactions
func GetPathParameters ¶
GetPathParameters extracts parameters from a path given its template
Types ¶
type APIDefinition ¶
type APIDefinition struct {
Paths map[string]map[string]Operation // path -> method -> operation
Components Components
BasePath string
Title string
Description string
Version string
}
APIDefinition stores the collected API information
func NewAPIDefinition ¶
func NewAPIDefinition(title, description, version, basePath string) *APIDefinition
NewAPIDefinition creates a new APIDefinition with default values
func (*APIDefinition) AddTransaction ¶
func (d *APIDefinition) AddTransaction(transaction proxy.APITransaction)
AddTransaction adds an API transaction to the definition
func (*APIDefinition) ToOpenAPI ¶
func (d *APIDefinition) ToOpenAPI() map[string]interface{}
ToOpenAPI converts the API definition to an OpenAPI 3.0 specification
type AuthDetector ¶
type AuthDetector struct {
// contains filtered or unexported fields
}
AuthDetector analyzes API traffic to detect authentication schemes
func NewAuthDetector ¶
func NewAuthDetector() *AuthDetector
NewAuthDetector creates a new auth detector
func (*AuthDetector) AnalyzeTransaction ¶
func (d *AuthDetector) AnalyzeTransaction(req *http.Request, resp *http.Response)
AnalyzeTransaction analyzes an API transaction for authentication information
func (*AuthDetector) GetAuthSchemes ¶
func (d *AuthDetector) GetAuthSchemes() []AuthScheme
GetAuthSchemes returns all detected authentication schemes
type AuthScheme ¶
type AuthScheme struct {
Type string // http, apiKey, oauth2, openIdConnect
Scheme string // basic, bearer, digest (for http type)
Description string
In string // header, query, cookie (for apiKey type)
Name string // header name or query parameter name
Format string // JWT, etc. (for bearer token)
Example string
}
AuthScheme represents an authentication scheme
type Components ¶
Components holds reusable OpenAPI components
type Encoding ¶
type Encoding struct {
ContentType string `json:"contentType,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
Style string `json:"style,omitempty"`
Explode bool `json:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty"`
}
Encoding represents an OpenAPI encoding
type Example ¶
type Example struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Value interface{} `json:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty"`
}
Example represents an OpenAPI example
type Header ¶
type Header struct {
Description string `json:"description,omitempty"`
Schema Schema `json:"schema"`
Example interface{} `json:"example,omitempty"`
}
Header represents an OpenAPI header
type MediaType ¶
type MediaType struct {
Schema Schema `json:"schema"`
Example interface{} `json:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty"`
Encoding map[string]Encoding `json:"encoding,omitempty"`
}
MediaType represents an OpenAPI media type
type Operation ¶
type Operation struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationID string `json:"operationId,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]Response `json:"responses,omitempty"`
Tags []string `json:"tags,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
}
Operation represents an OpenAPI operation
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // query, path, header, cookie
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema Schema `json:"schema"`
Example interface{} `json:"example,omitempty"`
}
Parameter represents an OpenAPI parameter
type PathPatternDetector ¶
type PathPatternDetector struct {
// contains filtered or unexported fields
}
PathPatternDetector detects path patterns from observed URLs
func NewPathPatternDetector ¶
func NewPathPatternDetector() *PathPatternDetector
NewPathPatternDetector creates a new path pattern detector
func (*PathPatternDetector) AddPath ¶
func (d *PathPatternDetector) AddPath(path string)
AddPath adds a path to the detector for analysis
func (*PathPatternDetector) AnalyzePatterns ¶
func (d *PathPatternDetector) AnalyzePatterns()
AnalyzePatterns analyzes all observed paths to detect patterns
func (*PathPatternDetector) GetPatterns ¶
func (d *PathPatternDetector) GetPatterns() map[string]string
GetPatterns returns all detected patterns
func (*PathPatternDetector) TemplatizePath ¶
func (d *PathPatternDetector) TemplatizePath(path string) string
TemplatizePath converts a concrete path to a templated path if it matches a pattern
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Content map[string]MediaType `json:"content"`
Required bool `json:"required,omitempty"`
}
RequestBody represents an OpenAPI request body
func MergeRequestBody ¶
func MergeRequestBody(bodies []*RequestBody) *RequestBody
MergeRequestBody merges request bodies from multiple examples
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
}
Response represents an OpenAPI response
func MergeResponse ¶
MergeResponse merges responses from multiple examples
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties map[string]Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Example interface{} `json:"example,omitempty"`
AllOf []Schema `json:"allOf,omitempty"`
OneOf []Schema `json:"oneOf,omitempty"`
AnyOf []Schema `json:"anyOf,omitempty"`
Not *Schema `json:"not,omitempty"`
Default interface{} `json:"default,omitempty"`
Nullable bool `json:"nullable,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
WriteOnly bool `json:"writeOnly,omitempty"`
XML map[string]string `json:"xml,omitempty"`
ExternalDocs map[string]string `json:"externalDocs,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
}
Schema represents an OpenAPI schema
func ApplyTypeInference ¶
ApplyTypeInference enhances an existing schema with improved type detection
type SchemaMerger ¶
type SchemaMerger struct {
// contains filtered or unexported fields
}
SchemaMerger merges multiple schemas into a single comprehensive schema
func NewSchemaMerger ¶
func NewSchemaMerger() *SchemaMerger
NewSchemaMerger creates a new schema merger
func (*SchemaMerger) AddSchema ¶
func (m *SchemaMerger) AddSchema(path, method string, schema Schema)
AddSchema adds a schema to the merger for the given path and method
func (*SchemaMerger) MergeSchemas ¶
func (m *SchemaMerger) MergeSchemas(path, method string) Schema
MergeSchemas merges all schemas for the given path and method
type TypeInferrer ¶
type TypeInferrer struct {
// contains filtered or unexported fields
}
TypeInferrer analyzes values to determine their types more intelligently
func NewTypeInferrer ¶
func NewTypeInferrer(maxSamples int) *TypeInferrer
NewTypeInferrer creates a new type inference engine
func (*TypeInferrer) AddSample ¶
func (t *TypeInferrer) AddSample(path string, value interface{})
AddSample adds a new sample value for analysis
func (*TypeInferrer) InferSchema ¶
func (t *TypeInferrer) InferSchema(path string) *Schema
InferSchema generates a refined schema based on collected samples
func (*TypeInferrer) ResetSamples ¶
func (t *TypeInferrer) ResetSamples()
ResetSamples clears all collected samples