Documentation
¶
Overview ¶
Package inference provides API schema inference from traffic
Package inference provides API schema inference from traffic
Index ¶
- type CapturedRequest
- type InferenceSettings
- type InferredParameter
- type MediaTypeObject
- type OpenAPIComponents
- type OpenAPIGenerator
- type OpenAPIInfo
- type OpenAPIParameter
- type OpenAPIRequestBody
- type OpenAPIServer
- type OpenAPISpec
- type OpenAPITag
- type Operation
- type PathItem
- type RequestCluster
- type Response
- type SchemaInferrer
- type SchemaObject
- type SecurityScheme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CapturedRequest ¶
type CapturedRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Path string `json:"path"`
Query map[string]string `json:"query"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
ContentType string `json:"content_type"`
Timestamp int64 `json:"timestamp"`
}
CapturedRequest represents a captured HTTP request
type InferenceSettings ¶
type InferenceSettings struct {
MinConfidence float64 `yaml:"min_confidence" json:"min_confidence"`
ClusterThreshold float64 `yaml:"cluster_threshold" json:"cluster_threshold"`
MaxExamples int `yaml:"max_examples" json:"max_examples"`
}
InferenceSettings holds inference configuration
type InferredParameter ¶
type InferredParameter struct {
Name string `json:"name"`
Location string `json:"location"` // path, query, header, body
InferredType string `json:"inferred_type"`
Required bool `json:"required"`
Examples []string `json:"examples"`
Confidence float64 `json:"confidence"`
Pattern string `json:"pattern,omitempty"`
}
InferredParameter represents an inferred API parameter
type MediaTypeObject ¶
type MediaTypeObject struct {
Schema SchemaObject `json:"schema"`
Example interface{} `json:"example,omitempty"`
}
MediaTypeObject represents a media type
type OpenAPIComponents ¶
type OpenAPIComponents struct {
Schemas map[string]SchemaObject `json:"schemas,omitempty"`
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"`
}
OpenAPIComponents represents components
type OpenAPIGenerator ¶
type OpenAPIGenerator struct {
// contains filtered or unexported fields
}
OpenAPIGenerator generates OpenAPI specs from inferred endpoints
func NewOpenAPIGenerator ¶
func NewOpenAPIGenerator(title, version, description string) *OpenAPIGenerator
NewOpenAPIGenerator creates a new OpenAPI generator
func (*OpenAPIGenerator) AddServer ¶
func (g *OpenAPIGenerator) AddServer(url string)
AddServer adds a server URL
func (*OpenAPIGenerator) Generate ¶
func (g *OpenAPIGenerator) Generate(endpoints []types.Endpoint) (*OpenAPISpec, error)
Generate generates an OpenAPI spec from endpoints
type OpenAPIInfo ¶
type OpenAPIInfo struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
}
OpenAPIInfo represents the info section
type OpenAPIParameter ¶
type OpenAPIParameter struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description,omitempty"`
Required bool `json:"required"`
Schema SchemaObject `json:"schema"`
Example interface{} `json:"example,omitempty"`
}
OpenAPIParameter represents a parameter
type OpenAPIRequestBody ¶
type OpenAPIRequestBody struct {
Description string `json:"description,omitempty"`
Required bool `json:"required"`
Content map[string]MediaTypeObject `json:"content"`
}
OpenAPIRequestBody represents a request body
type OpenAPIServer ¶
type OpenAPIServer struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
}
OpenAPIServer represents a server
type OpenAPISpec ¶
type OpenAPISpec struct {
OpenAPI string `json:"openapi"`
Info OpenAPIInfo `json:"info"`
Servers []OpenAPIServer `json:"servers,omitempty"`
Paths map[string]PathItem `json:"paths"`
Components *OpenAPIComponents `json:"components,omitempty"`
Tags []OpenAPITag `json:"tags,omitempty"`
}
OpenAPISpec represents an OpenAPI 3.0 specification
func (*OpenAPISpec) ToJSON ¶
func (spec *OpenAPISpec) ToJSON() ([]byte, error)
ToJSON serializes the spec to JSON
func (*OpenAPISpec) ToYAML ¶
func (spec *OpenAPISpec) ToYAML() (string, error)
ToYAML serializes the spec to YAML format
type OpenAPITag ¶
type OpenAPITag struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
OpenAPITag represents a tag
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationID string `json:"operationId,omitempty"`
Parameters []OpenAPIParameter `json:"parameters,omitempty"`
RequestBody *OpenAPIRequestBody `json:"requestBody,omitempty"`
Responses map[string]Response `json:"responses"`
Security []map[string][]string `json:"security,omitempty"`
}
Operation represents an operation
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"`
Post *Operation `json:"post,omitempty"`
Put *Operation `json:"put,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Options *Operation `json:"options,omitempty"`
Head *Operation `json:"head,omitempty"`
}
PathItem represents a path item
type RequestCluster ¶
type RequestCluster struct {
PathPattern string `json:"path_pattern"`
Method string `json:"method"`
Requests []CapturedRequest `json:"requests"`
InferredParams []InferredParameter `json:"inferred_params"`
Examples []string `json:"examples"`
Count int `json:"count"`
}
RequestCluster represents a group of similar requests
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaTypeObject `json:"content,omitempty"`
}
Response represents a response
type SchemaInferrer ¶
type SchemaInferrer struct {
// contains filtered or unexported fields
}
SchemaInferrer infers API schema from captured requests
func NewSchemaInferrer ¶
func NewSchemaInferrer(settings InferenceSettings) *SchemaInferrer
NewSchemaInferrer creates a new schema inferrer
func (*SchemaInferrer) AddRequest ¶
func (si *SchemaInferrer) AddRequest(req CapturedRequest)
AddRequest adds a captured request for inference
func (*SchemaInferrer) AddRequests ¶
func (si *SchemaInferrer) AddRequests(reqs []CapturedRequest)
AddRequests adds multiple captured requests
func (*SchemaInferrer) GetClusters ¶
func (si *SchemaInferrer) GetClusters() map[string]*RequestCluster
GetClusters returns the request clusters
type SchemaObject ¶
type SchemaObject struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties map[string]SchemaObject `json:"properties,omitempty"`
Items *SchemaObject `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
Example interface{} `json:"example,omitempty"`
Enum []string `json:"enum,omitempty"`
}
SchemaObject represents a schema