Documentation
¶
Index ¶
Constants ¶
const ( ObjectType = "object" ArrayType = "array" IntegerType = "integer" NumberType = "number" StringType = "string" BooleanType = "boolean" NullType = "null" ArrayOfStringType = "array_of_string" ArrayOfArrayType = "array_of_array" ArrayOfObjectType = "array_of_object" )
OpenAPI types
const ( MethodGet = "GET" MethodPost = "POST" MethodPut = "PUT" MethodDelete = "DELETE" MethodPatch = "PATCH" MethodHead = "HEAD" MethodOptions = "OPTIONS" )
HTTP methods
const ( SecurityLocationHeader = "header" SecurityLocationQuery = "query" SecurityLocationCookie = "cookie" )
Security locations
const ( ContentTypeFormUrlencoded = "application/x-www-form-urlencoded" ContentTypeJSON = "application/json" )
Content types
const (
SecurityTypeApiKey = "apiKey"
)
Security types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Documentation ¶
type Documentation struct {
config.Documentation
Options map[string]string // Additional options for parsing
}
Documentation represents information about API documentation
type Endpoint ¶
type Endpoint struct {
Path string // API path
Method string // HTTP method
Description string // Description of the endpoint
Summary string // Short summary of the endpoint
Security []map[string][]string // Security requirements for the endpoint
Parameters []*Parameter // Parameters accepted by the endpoint
Responses map[string]*Response // Responses by status code
Metadata map[string]interface{} // Additional metadata
Tags []string // Tags for categorizing the endpoint
Extensions map[string]interface{} // OpenAPI extensions
RequestBody *RequestBody // Request body definition
Deprecated bool // Whether the endpoint is deprecated
OperationID string // Operation ID
Schemas []*Schema // Schemas for the endpoint
SecuritySchemas map[string]*SecuritySchema // Security schemas for the endpoint
Protected bool // Whether the endpoint is protected
}
Endpoint represents an API endpoint
type HTTPDocumentParser ¶
type HTTPDocumentParser interface {
Parse(r io.Reader, urlEntity *config.URLEntity, protectedEndpoints []string) ([]Endpoint, error)
}
HTTPDocumentParser defines the interface for HTTP document parsers
type HTTPParser ¶
type HTTPParser struct {
Name string
Client *http.Client
// Add a flag to control whether to use saved samples
UseSamples bool
// Add a directory path for samples
SamplesDir string
DocParser HTTPDocumentParser
}
HTTPParser is an implementation of the Parser interface for HTTP-based APIs
func (*HTTPParser) Parse ¶
func (p *HTTPParser) Parse(ctx context.Context, doc Documentation) ([]Endpoint, error)
Parse processes the API documentation and returns the extracted endpoints
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"`
}
MediaType represents a media type in request or response
type Parameter ¶
type Parameter struct {
Name string // Parameter name
Required bool // Whether the parameter is required
Description string // Description of the parameter
In string // Parameter location (query, path, header, cookie)
Schema *Schema // Parameter schema
}
Parameter represents an endpoint parameter
type Parser ¶
type Parser interface {
// Parse parses the documentation and returns endpoints
Parse(ctx context.Context, doc Documentation) ([]Endpoint, error)
// CheckVersion checks if the documentation version has changed
CheckVersion(ctx context.Context, doc Documentation) (bool, time.Time, error)
}
Parser defines the interface for API documentation parsers
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Content map[string]*MediaType `json:"content,omitempty"`
Required bool `json:"required,omitempty"`
}
RequestBody represents the body of a request
type Response ¶
type Response struct {
Description string // Description of the response
Schema string // Response schema
Content map[string]*MediaType // Response content by media type
}
Response represents an API response
type Schema ¶
type Schema struct {
OneOf []*Schema `json:"oneOf,omitempty"`
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Default interface{} `json:"default,omitempty"`
Example interface{} `json:"example,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
ExclusiveMin bool `json:"exclusiveMinimum,omitempty"`
ExclusiveMax bool `json:"exclusiveMaximum,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
// Numeric constraints
Min *float64 `json:"minimum,omitempty"`
Max *float64 `json:"maximum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
// String constraints
MinLength uint64 `json:"minLength,omitempty"`
MaxLength *uint64 `json:"maxLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
// Array constraints
MinItems uint64 `json:"minItems,omitempty"`
MaxItems *uint64 `json:"maxItems,omitempty"`
Items *Schema `json:"items,omitempty"`
// Object constraints
Required []string `json:"required,omitempty"`
// Additional fields
Properties map[string]*Schema `json:"properties,omitempty"`
AdditionalProperties *Schema `json:"additionalProperties,omitempty"`
// OpenAPI specific fields
Ref string `json:"$ref,omitempty"`
// Vendor extensions (x-* fields)
Extensions map[string]interface{} `json:"-"`
}
Schema represents a JSON Schema definition
type SecuritySchema ¶
type SecuritySchema struct {
Type string `json:"type,omitempty"`
In string `json:"in,omitempty"`
Name string `json:"name,omitempty"`
}
Security represents a security requirement for an endpoint