use anyhow::Result;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use tokio::sync::{Arc, RwLock};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiDocumentationConfig {
pub enabled: bool,
pub auto_generation: bool,
pub output_formats: Vec<DocumentationFormat>,
pub openapi_version: String,
pub include_examples: bool,
pub include_schemas: bool,
pub include_security: bool,
pub validation_enabled: bool,
pub interactive_docs: InteractiveDocsConfig,
pub versioning: VersioningConfig,
pub generation: GenerationConfig,
pub publishing: PublishingConfig,
pub customization: CustomizationConfig,
pub compliance: ComplianceConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InteractiveDocsConfig {
pub enabled: bool,
pub swagger_ui: bool,
pub redoc: bool,
pub custom_theme: Option<String>,
pub try_it_out: bool,
pub auth_integration: bool,
pub sandbox_environment: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersioningConfig {
pub auto_versioning: bool,
pub semantic_versioning: bool,
pub changelog_generation: bool,
pub backwards_compatibility_check: bool,
pub deprecation_warnings: bool,
pub migration_guides: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationConfig {
pub source_scanning: SourceScanningConfig,
pub code_analysis: CodeAnalysisConfig,
pub example_generation: ExampleGenerationConfig,
pub schema_extraction: SchemaExtractionConfig,
pub validation_rules: ValidationRulesConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceScanningConfig {
pub scan_paths: Vec<PathBuf>,
pub file_patterns: Vec<String>,
pub exclude_patterns: Vec<String>,
pub deep_scan: bool,
pub dependency_analysis: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeAnalysisConfig {
pub extract_comments: bool,
pub infer_types: bool,
pub analyze_examples: bool,
pub error_analysis: bool,
pub performance_hints: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExampleGenerationConfig {
pub auto_generate: bool,
pub realistic_data: bool,
pub edge_cases: bool,
pub error_examples: bool,
pub performance_examples: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SchemaExtractionConfig {
pub auto_extract: bool,
pub validate_schemas: bool,
pub optimize_schemas: bool,
pub include_descriptions: bool,
pub format_validation: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationRulesConfig {
pub syntax_validation: bool,
pub semantic_validation: bool,
pub completeness_check: bool,
pub consistency_check: bool,
pub best_practices: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublishingConfig {
pub auto_publish: bool,
pub publish_targets: Vec<PublishTarget>,
pub cdn_integration: bool,
pub versioned_urls: bool,
pub custom_domains: Vec<String>,
pub access_control: AccessControlConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublishTarget {
pub target_type: PublishTargetType,
pub url: String,
pub auth_config: Option<AuthConfig>,
pub custom_headers: HashMap<String, String>,
pub retry_config: RetryConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PublishTargetType {
S3Bucket,
HttpEndpoint,
FileSystem,
GitRepository,
DocumentationPortal,
ApiGateway,
ContainerRegistry,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfig {
pub auth_type: AuthType,
pub credentials: HashMap<String, String>,
pub token_refresh: bool,
pub token_cache_duration: std::time::Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AuthType {
ApiKey,
OAuth2,
BasicAuth,
BearerToken,
CustomHeader,
MutualTls,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RetryConfig {
pub max_retries: u32,
pub initial_delay: std::time::Duration,
pub max_delay: std::time::Duration,
pub backoff_multiplier: f64,
pub retry_on_status: Vec<u16>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccessControlConfig {
pub public_access: bool,
pub required_roles: Vec<String>,
pub ip_whitelist: Vec<String>,
pub rate_limiting: bool,
pub audit_access: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomizationConfig {
pub branding: BrandingConfig,
pub layout: LayoutConfig,
pub styling: StylingConfig,
pub navigation: NavigationConfig,
pub content: ContentConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BrandingConfig {
pub logo_url: Option<String>,
pub company_name: Option<String>,
pub primary_color: Option<String>,
pub secondary_color: Option<String>,
pub favicon_url: Option<String>,
pub custom_css: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutConfig {
pub sidebar_navigation: bool,
pub top_navigation: bool,
pub search_enabled: bool,
pub table_of_contents: bool,
pub breadcrumbs: bool,
pub responsive_design: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StylingConfig {
pub theme: DocumentationTheme,
pub syntax_highlighting: bool,
pub dark_mode: bool,
pub custom_fonts: Vec<String>,
pub code_style: CodeStyle,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DocumentationTheme {
Default,
Modern,
Minimal,
Corporate,
Developer,
Custom(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CodeStyle {
Github,
Monokai,
Solarized,
VisualStudio,
Atom,
Custom(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NavigationConfig {
pub group_by_tags: bool,
pub sort_alphabetically: bool,
pub show_method_colors: bool,
pub expand_operations: bool,
pub hide_deprecated: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContentConfig {
pub show_extensions: bool,
pub show_common_responses: bool,
pub detailed_examples: bool,
pub performance_metrics: bool,
pub security_notes: bool,
pub migration_notes: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplianceConfig {
pub gdpr_compliance: bool,
pub hipaa_compliance: bool,
pub sox_compliance: bool,
pub pci_compliance: bool,
pub data_classification: bool,
pub privacy_annotations: bool,
pub security_classifications: Vec<SecurityClassification>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityClassification {
pub level: SecurityLevel,
pub description: String,
pub requirements: Vec<String>,
pub handling_instructions: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SecurityLevel {
Public,
Internal,
Confidential,
Restricted,
TopSecret,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DocumentationFormat {
OpenApiJson,
OpenApiYaml,
AsyncApi,
Postman,
Insomnia,
SwaggerUi,
Redoc,
Markdown,
Html,
Pdf,
Word,
Confluence,
Notion,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiDocumentation {
pub id: Uuid,
pub name: String,
pub description: Option<String>,
pub version: String,
pub base_url: String,
pub contact: Option<ContactInfo>,
pub license: Option<LicenseInfo>,
pub servers: Vec<ServerInfo>,
pub paths: HashMap<String, PathItem>,
pub components: Components,
pub security: Vec<SecurityRequirement>,
pub tags: Vec<Tag>,
pub external_docs: Option<ExternalDocumentation>,
pub extensions: HashMap<String, serde_json::Value>,
pub metadata: DocumentationMetadata,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContactInfo {
pub name: Option<String>,
pub email: Option<String>,
pub url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LicenseInfo {
pub name: String,
pub url: Option<String>,
pub identifier: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerInfo {
pub url: String,
pub description: Option<String>,
pub variables: HashMap<String, ServerVariable>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerVariable {
pub default: String,
pub description: Option<String>,
pub enum_values: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PathItem {
pub summary: Option<String>,
pub description: Option<String>,
pub operations: HashMap<HttpMethod, Operation>,
pub servers: Option<Vec<ServerInfo>>,
pub parameters: Vec<Parameter>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum HttpMethod {
Get,
Post,
Put,
Delete,
Patch,
Head,
Options,
Trace,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Operation {
pub operation_id: Option<String>,
pub summary: Option<String>,
pub description: Option<String>,
pub tags: Vec<String>,
pub parameters: Vec<Parameter>,
pub request_body: Option<RequestBody>,
pub responses: HashMap<String, Response>,
pub callbacks: HashMap<String, Callback>,
pub deprecated: bool,
pub security: Vec<SecurityRequirement>,
pub servers: Option<Vec<ServerInfo>>,
pub external_docs: Option<ExternalDocumentation>,
pub examples: Vec<OperationExample>,
pub performance_info: Option<PerformanceInfo>,
pub rate_limiting: Option<RateLimitInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Parameter {
pub name: String,
pub location: ParameterLocation,
pub description: Option<String>,
pub required: bool,
pub deprecated: bool,
pub allow_empty_value: bool,
pub style: Option<ParameterStyle>,
pub explode: bool,
pub allow_reserved: bool,
pub schema: Option<Schema>,
pub example: Option<serde_json::Value>,
pub examples: HashMap<String, Example>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ParameterLocation {
Query,
Header,
Path,
Cookie,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ParameterStyle {
Matrix,
Label,
Form,
Simple,
SpaceDelimited,
PipeDelimited,
DeepObject,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequestBody {
pub description: Option<String>,
pub content: HashMap<String, MediaType>,
pub required: bool,
pub examples: Vec<RequestExample>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MediaType {
pub schema: Option<Schema>,
pub example: Option<serde_json::Value>,
pub examples: HashMap<String, Example>,
pub encoding: HashMap<String, Encoding>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Encoding {
pub content_type: Option<String>,
pub headers: HashMap<String, Header>,
pub style: Option<ParameterStyle>,
pub explode: bool,
pub allow_reserved: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Header {
pub description: Option<String>,
pub required: bool,
pub deprecated: bool,
pub allow_empty_value: bool,
pub style: Option<ParameterStyle>,
pub explode: bool,
pub allow_reserved: bool,
pub schema: Option<Schema>,
pub example: Option<serde_json::Value>,
pub examples: HashMap<String, Example>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Response {
pub description: String,
pub headers: HashMap<String, Header>,
pub content: HashMap<String, MediaType>,
pub links: HashMap<String, Link>,
pub examples: Vec<ResponseExample>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Link {
pub operation_ref: Option<String>,
pub operation_id: Option<String>,
pub parameters: HashMap<String, serde_json::Value>,
pub request_body: Option<serde_json::Value>,
pub description: Option<String>,
pub server: Option<ServerInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Callback {
pub expressions: HashMap<String, PathItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Components {
pub schemas: HashMap<String, Schema>,
pub responses: HashMap<String, Response>,
pub parameters: HashMap<String, Parameter>,
pub examples: HashMap<String, Example>,
pub request_bodies: HashMap<String, RequestBody>,
pub headers: HashMap<String, Header>,
pub security_schemes: HashMap<String, SecurityScheme>,
pub links: HashMap<String, Link>,
pub callbacks: HashMap<String, Callback>,
pub path_items: HashMap<String, PathItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Schema {
pub schema_type: Option<SchemaType>,
pub format: Option<String>,
pub description: Option<String>,
pub default: Option<serde_json::Value>,
pub example: Option<serde_json::Value>,
pub examples: Vec<serde_json::Value>,
pub title: Option<String>,
pub multiple_of: Option<f64>,
pub maximum: Option<f64>,
pub exclusive_maximum: bool,
pub minimum: Option<f64>,
pub exclusive_minimum: bool,
pub max_length: Option<usize>,
pub min_length: Option<usize>,
pub pattern: Option<String>,
pub max_items: Option<usize>,
pub min_items: Option<usize>,
pub unique_items: bool,
pub max_properties: Option<usize>,
pub min_properties: Option<usize>,
pub required: Vec<String>,
pub enum_values: Option<Vec<serde_json::Value>>,
pub properties: HashMap<String, Box<Schema>>,
pub additional_properties: Option<Box<Schema>>,
pub items: Option<Box<Schema>>,
pub all_of: Vec<Schema>,
pub one_of: Vec<Schema>,
pub any_of: Vec<Schema>,
pub not: Option<Box<Schema>>,
pub discriminator: Option<Discriminator>,
pub read_only: bool,
pub write_only: bool,
pub deprecated: bool,
pub nullable: bool,
pub external_docs: Option<ExternalDocumentation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SchemaType {
String,
Number,
Integer,
Boolean,
Array,
Object,
Null,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Discriminator {
pub property_name: String,
pub mapping: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Example {
pub summary: Option<String>,
pub description: Option<String>,
pub value: Option<serde_json::Value>,
pub external_value: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityScheme {
pub scheme_type: SecuritySchemeType,
pub description: Option<String>,
pub name: Option<String>,
pub location: Option<SecurityLocation>,
pub scheme: Option<String>,
pub bearer_format: Option<String>,
pub flows: Option<OAuthFlows>,
pub open_id_connect_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SecuritySchemeType {
ApiKey,
Http,
OAuth2,
OpenIdConnect,
MutualTls,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SecurityLocation {
Query,
Header,
Cookie,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthFlows {
pub implicit: Option<OAuthFlow>,
pub password: Option<OAuthFlow>,
pub client_credentials: Option<OAuthFlow>,
pub authorization_code: Option<OAuthFlow>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthFlow {
pub authorization_url: Option<String>,
pub token_url: Option<String>,
pub refresh_url: Option<String>,
pub scopes: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityRequirement {
pub schemes: HashMap<String, Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag {
pub name: String,
pub description: Option<String>,
pub external_docs: Option<ExternalDocumentation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExternalDocumentation {
pub description: Option<String>,
pub url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperationExample {
pub name: String,
pub summary: Option<String>,
pub description: Option<String>,
pub request: Option<serde_json::Value>,
pub response: Option<serde_json::Value>,
pub curl_example: Option<String>,
pub language_examples: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequestExample {
pub name: String,
pub summary: Option<String>,
pub description: Option<String>,
pub content_type: String,
pub body: serde_json::Value,
pub headers: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponseExample {
pub name: String,
pub summary: Option<String>,
pub description: Option<String>,
pub status_code: u16,
pub content_type: String,
pub body: serde_json::Value,
pub headers: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceInfo {
pub average_response_time: Option<std::time::Duration>,
pub max_response_time: Option<std::time::Duration>,
pub throughput: Option<f64>,
pub error_rate: Option<f64>,
pub sla_targets: HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RateLimitInfo {
pub requests_per_minute: Option<u32>,
pub requests_per_hour: Option<u32>,
pub requests_per_day: Option<u32>,
pub burst_limit: Option<u32>,
pub quota_reset: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentationMetadata {
pub generated_by: String,
pub generation_date: DateTime<Utc>,
pub source_hash: Option<String>,
pub api_version: String,
pub documentation_version: String,
pub tags: Vec<String>,
pub categories: Vec<String>,
pub audience: DocumentationAudience,
pub maturity_level: MaturityLevel,
pub compliance_status: ComplianceStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DocumentationAudience {
Public,
Internal,
Partner,
Beta,
Alpha,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MaturityLevel {
Alpha,
Beta,
Stable,
Deprecated,
Sunset,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ComplianceStatus {
Compliant,
PartiallyCompliant,
NonCompliant,
UnderReview,
NotApplicable,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentationGeneration {
pub id: Uuid,
pub documentation_id: Uuid,
pub generation_type: GenerationType,
pub source_files: Vec<PathBuf>,
pub output_formats: Vec<DocumentationFormat>,
pub status: GenerationStatus,
pub started_at: DateTime<Utc>,
pub completed_at: Option<DateTime<Utc>>,
pub duration: Option<std::time::Duration>,
pub artifacts: Vec<GenerationArtifact>,
pub errors: Vec<GenerationError>,
pub warnings: Vec<GenerationWarning>,
pub statistics: GenerationStatistics,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GenerationType {
Manual,
Automatic,
Scheduled,
Triggered,
Incremental,
Full,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GenerationStatus {
Pending,
InProgress,
Completed,
Failed,
Cancelled,
PartiallyCompleted,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationArtifact {
pub artifact_type: ArtifactType,
pub file_path: PathBuf,
pub size_bytes: u64,
pub checksum: String,
pub url: Option<String>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ArtifactType {
OpenApiSpec,
SwaggerUi,
RedocHtml,
MarkdownDocs,
PdfReport,
PostmanCollection,
InsomniaWorkspace,
SdkPackage,
ClientLibrary,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationError {
pub error_type: ErrorType,
pub message: String,
pub source_file: Option<PathBuf>,
pub line_number: Option<u32>,
pub severity: ErrorSeverity,
pub suggestion: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ErrorType {
SyntaxError,
ValidationError,
SchemaError,
TypeInferenceError,
MissingDocumentation,
InconsistentDocumentation,
SecurityIssue,
PerformanceIssue,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ErrorSeverity {
Info,
Warning,
Error,
Critical,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationWarning {
pub warning_type: WarningType,
pub message: String,
pub source_file: Option<PathBuf>,
pub line_number: Option<u32>,
pub suggestion: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum WarningType {
MissingDescription,
MissingExample,
DeprecatedFeature,
IncompleteDocumentation,
StyleViolation,
BestPracticeViolation,
PerformanceHint,
SecurityHint,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationStatistics {
pub total_endpoints: u32,
pub documented_endpoints: u32,
pub total_schemas: u32,
pub documented_schemas: u32,
pub examples_generated: u32,
pub validation_errors: u32,
pub validation_warnings: u32,
pub coverage_percentage: f64,
pub quality_score: f64,
}
pub struct ApiDocumentationSystem {
config: ApiDocumentationConfig,
documentation_store: Arc<RwLock<HashMap<Uuid, ApiDocumentation>>>,
generation_store: Arc<RwLock<HashMap<Uuid, DocumentationGeneration>>>,
generator_engine: Arc<RwLock<DocumentationGenerator>>,
validator_engine: Arc<RwLock<DocumentationValidator>>,
publisher_engine: Arc<RwLock<DocumentationPublisher>>,
template_engine: Arc<RwLock<TemplateEngine>>,
analytics_engine: Arc<RwLock<DocumentationAnalytics>>,
}
pub struct DocumentationGenerator {
source_analyzers: HashMap<String, Box<dyn SourceAnalyzer>>,
schema_extractors: HashMap<String, Box<dyn SchemaExtractor>>,
example_generators: HashMap<String, Box<dyn ExampleGenerator>>,
format_generators: HashMap<DocumentationFormat, Box<dyn FormatGenerator>>,
metadata_extractors: Vec<Box<dyn MetadataExtractor>>,
}
#[async_trait::async_trait]
pub trait SourceAnalyzer: Send + Sync {
async fn analyze(&self, source_path: &PathBuf) -> Result<SourceAnalysis>;
async fn extract_endpoints(&self, source: &SourceAnalysis) -> Result<Vec<EndpointInfo>>;
async fn extract_types(&self, source: &SourceAnalysis) -> Result<Vec<TypeInfo>>;
fn supported_extensions(&self) -> Vec<String>;
}
#[async_trait::async_trait]
pub trait SchemaExtractor: Send + Sync {
async fn extract_schema(&self, type_info: &TypeInfo) -> Result<Schema>;
async fn validate_schema(&self, schema: &Schema) -> Result<Vec<ValidationIssue>>;
async fn optimize_schema(&self, schema: &Schema) -> Result<Schema>;
}
#[async_trait::async_trait]
pub trait ExampleGenerator: Send + Sync {
async fn generate_request_example(&self, operation: &Operation) -> Result<RequestExample>;
async fn generate_response_example(&self, response: &Response) -> Result<ResponseExample>;
async fn generate_curl_example(&self, operation: &Operation) -> Result<String>;
async fn generate_language_examples(&self, operation: &Operation) -> Result<HashMap<String, String>>;
}
#[async_trait::async_trait]
pub trait FormatGenerator: Send + Sync {
async fn generate(&self, documentation: &ApiDocumentation) -> Result<GenerationArtifact>;
async fn validate_output(&self, artifact: &GenerationArtifact) -> Result<Vec<ValidationIssue>>;
fn output_format(&self) -> DocumentationFormat;
}
#[async_trait::async_trait]
pub trait MetadataExtractor: Send + Sync {
async fn extract(&self, source_path: &PathBuf) -> Result<HashMap<String, String>>;
fn metadata_type(&self) -> String;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceAnalysis {
pub file_path: PathBuf,
pub language: String,
pub framework: Option<String>,
pub version: Option<String>,
pub ast: serde_json::Value,
pub dependencies: Vec<String>,
pub exports: Vec<String>,
pub imports: Vec<String>,
pub annotations: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointInfo {
pub path: String,
pub method: HttpMethod,
pub handler_function: String,
pub parameters: Vec<ParameterInfo>,
pub request_type: Option<String>,
pub response_type: Option<String>,
pub documentation: Option<String>,
pub examples: Vec<String>,
pub middleware: Vec<String>,
pub security: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParameterInfo {
pub name: String,
pub parameter_type: String,
pub location: ParameterLocation,
pub required: bool,
pub description: Option<String>,
pub default_value: Option<String>,
pub validation_rules: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeInfo {
pub name: String,
pub type_kind: TypeKind,
pub fields: Vec<FieldInfo>,
pub methods: Vec<MethodInfo>,
pub documentation: Option<String>,
pub examples: Vec<String>,
pub constraints: Vec<String>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypeKind {
Struct,
Enum,
Union,
Interface,
Class,
Trait,
Type,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldInfo {
pub name: String,
pub field_type: String,
pub required: bool,
pub description: Option<String>,
pub default_value: Option<String>,
pub validation_rules: Vec<String>,
pub examples: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MethodInfo {
pub name: String,
pub parameters: Vec<ParameterInfo>,
pub return_type: Option<String>,
pub description: Option<String>,
pub examples: Vec<String>,
pub visibility: Visibility,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Visibility {
Public,
Private,
Protected,
Internal,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationIssue {
pub issue_type: ValidationIssueType,
pub severity: ErrorSeverity,
pub message: String,
pub location: Option<String>,
pub suggestion: Option<String>,
pub rule_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ValidationIssueType {
MissingField,
InvalidType,
InvalidFormat,
MissingDocumentation,
InconsistentNaming,
SecurityVulnerability,
PerformanceIssue,
BestPracticeViolation,
}
pub struct DocumentationValidator {
validation_rules: Vec<Box<dyn ValidationRule>>,
schema_validators: HashMap<String, Box<dyn SchemaValidator>>,
style_checkers: Vec<Box<dyn StyleChecker>>,
security_analyzers: Vec<Box<dyn SecurityAnalyzer>>,
compliance_checkers: HashMap<String, Box<dyn ComplianceChecker>>,
}
#[async_trait::async_trait]
pub trait ValidationRule: Send + Sync {
async fn validate(&self, documentation: &ApiDocumentation) -> Result<Vec<ValidationIssue>>;
fn rule_id(&self) -> String;
fn rule_description(&self) -> String;
fn severity(&self) -> ErrorSeverity;
}
#[async_trait::async_trait]
pub trait SchemaValidator: Send + Sync {
async fn validate_schema(&self, schema: &Schema) -> Result<Vec<ValidationIssue>>;
fn schema_type(&self) -> String;
}
#[async_trait::async_trait]
pub trait StyleChecker: Send + Sync {
async fn check_style(&self, documentation: &ApiDocumentation) -> Result<Vec<ValidationIssue>>;
fn style_guide(&self) -> String;
}
#[async_trait::async_trait]
pub trait SecurityAnalyzer: Send + Sync {
async fn analyze_security(&self, documentation: &ApiDocumentation) -> Result<Vec<ValidationIssue>>;
fn security_framework(&self) -> String;
}
#[async_trait::async_trait]
pub trait ComplianceChecker: Send + Sync {
async fn check_compliance(&self, documentation: &ApiDocumentation) -> Result<Vec<ValidationIssue>>;
fn compliance_standard(&self) -> String;
}
pub struct DocumentationPublisher {
publishers: HashMap<PublishTargetType, Box<dyn Publisher>>,
cdn_manager: Option<Box<dyn CdnManager>>,
access_manager: Arc<RwLock<AccessManager>>,
notification_manager: Arc<RwLock<NotificationManager>>,
}
#[async_trait::async_trait]
pub trait Publisher: Send + Sync {
async fn publish(&self, artifact: &GenerationArtifact, target: &PublishTarget) -> Result<PublishResult>;
async fn unpublish(&self, artifact_id: &str, target: &PublishTarget) -> Result<()>;
async fn get_status(&self, artifact_id: &str, target: &PublishTarget) -> Result<PublishStatus>;
fn target_type(&self) -> PublishTargetType;
}
#[async_trait::async_trait]
pub trait CdnManager: Send + Sync {
async fn upload_to_cdn(&self, artifact: &GenerationArtifact) -> Result<String>;
async fn invalidate_cache(&self, urls: &[String]) -> Result<()>;
async fn get_cdn_stats(&self, url: &str) -> Result<CdnStats>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublishResult {
pub publish_id: Uuid,
pub target_url: String,
pub status: PublishStatus,
pub published_at: DateTime<Utc>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PublishStatus {
Pending,
InProgress,
Published,
Failed,
Retrying,
Cancelled,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CdnStats {
pub total_requests: u64,
pub cache_hit_ratio: f64,
pub bandwidth_used: u64,
pub geographic_distribution: HashMap<String, u64>,
}
pub struct AccessManager {
access_policies: HashMap<String, AccessPolicy>,
rate_limiters: HashMap<String, RateLimiter>,
audit_logger: Box<dyn AuditLogger>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccessPolicy {
pub policy_id: String,
pub allowed_ips: Vec<String>,
pub blocked_ips: Vec<String>,
pub required_roles: Vec<String>,
pub time_restrictions: Vec<TimeRestriction>,
pub geographic_restrictions: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeRestriction {
pub start_time: String,
pub end_time: String,
pub timezone: String,
pub days_of_week: Vec<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RateLimiter {
pub requests_per_minute: u32,
pub requests_per_hour: u32,
pub burst_capacity: u32,
pub window_size: std::time::Duration,
}
#[async_trait::async_trait]
pub trait AuditLogger: Send + Sync {
async fn log_access(&self, event: &AccessEvent) -> Result<()>;
async fn log_generation(&self, event: &GenerationEvent) -> Result<()>;
async fn log_publication(&self, event: &PublicationEvent) -> Result<()>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccessEvent {
pub timestamp: DateTime<Utc>,
pub user_id: Option<String>,
pub ip_address: String,
pub user_agent: String,
pub resource_path: String,
pub method: String,
pub status_code: u16,
pub response_time: std::time::Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerationEvent {
pub timestamp: DateTime<Utc>,
pub generation_id: Uuid,
pub user_id: Option<String>,
pub generation_type: GenerationType,
pub source_files: Vec<PathBuf>,
pub status: GenerationStatus,
pub duration: Option<std::time::Duration>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublicationEvent {
pub timestamp: DateTime<Utc>,
pub publication_id: Uuid,
pub user_id: Option<String>,
pub target: PublishTargetType,
pub artifact_id: Uuid,
pub status: PublishStatus,
}
pub struct NotificationManager {
notification_channels: HashMap<String, Box<dyn NotificationChannel>>,
subscription_manager: SubscriptionManager,
}
#[async_trait::async_trait]
pub trait NotificationChannel: Send + Sync {
async fn send_notification(&self, notification: &Notification) -> Result<()>;
fn channel_type(&self) -> String;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Notification {
pub notification_type: NotificationType,
pub title: String,
pub message: String,
pub priority: NotificationPriority,
pub timestamp: DateTime<Utc>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NotificationType {
GenerationCompleted,
GenerationFailed,
PublicationCompleted,
PublicationFailed,
ValidationError,
SecurityAlert,
PerformanceAlert,
MaintenanceNotice,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NotificationPriority {
Low,
Normal,
High,
Critical,
Emergency,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionManager {
subscriptions: HashMap<String, Vec<Subscription>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Subscription {
pub subscriber_id: String,
pub notification_types: Vec<NotificationType>,
pub channels: Vec<String>,
pub filters: HashMap<String, String>,
pub active: bool,
}
pub struct TemplateEngine {
templates: HashMap<String, Template>,
theme_manager: ThemeManager,
asset_manager: AssetManager,
customization_engine: CustomizationEngine,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Template {
pub template_id: String,
pub name: String,
pub description: String,
pub template_type: TemplateType,
pub content: String,
pub variables: Vec<TemplateVariable>,
pub partials: HashMap<String, String>,
pub assets: Vec<String>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TemplateType {
Html,
Markdown,
LaTeX,
Json,
Xml,
Custom(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemplateVariable {
pub name: String,
pub variable_type: String,
pub description: String,
pub default_value: Option<String>,
pub required: bool,
}
pub struct ThemeManager {
themes: HashMap<String, Theme>,
active_theme: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Theme {
pub theme_id: String,
pub name: String,
pub description: String,
pub colors: ColorScheme,
pub typography: Typography,
pub layout: LayoutSettings,
pub assets: Vec<Asset>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColorScheme {
pub primary: String,
pub secondary: String,
pub background: String,
pub text: String,
pub accent: String,
pub success: String,
pub warning: String,
pub error: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Typography {
pub font_family: String,
pub font_sizes: HashMap<String, String>,
pub line_heights: HashMap<String, String>,
pub font_weights: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayoutSettings {
pub max_width: String,
pub sidebar_width: String,
pub header_height: String,
pub footer_height: String,
pub spacing_unit: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Asset {
pub asset_type: AssetType,
pub path: String,
pub content: Option<String>,
pub url: Option<String>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AssetType {
Css,
JavaScript,
Image,
Font,
Icon,
Video,
Audio,
Other(String),
}
pub struct AssetManager {
assets: HashMap<String, Asset>,
cdn_config: Option<CdnConfig>,
optimization_settings: OptimizationSettings,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CdnConfig {
pub base_url: String,
pub cache_duration: std::time::Duration,
pub compression_enabled: bool,
pub regions: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationSettings {
pub minify_css: bool,
pub minify_js: bool,
pub optimize_images: bool,
pub inline_critical_assets: bool,
pub lazy_load_assets: bool,
}
pub struct CustomizationEngine {
customizations: HashMap<String, Customization>,
validation_rules: Vec<Box<dyn CustomizationValidator>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Customization {
pub customization_id: String,
pub target_element: String,
pub customization_type: CustomizationType,
pub value: serde_json::Value,
pub conditions: Vec<Condition>,
pub priority: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CustomizationType {
Style,
Content,
Layout,
Behavior,
Data,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Condition {
pub field: String,
pub operator: ConditionOperator,
pub value: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ConditionOperator {
Equals,
NotEquals,
Contains,
StartsWith,
EndsWith,
GreaterThan,
LessThan,
In,
NotIn,
}
#[async_trait::async_trait]
pub trait CustomizationValidator: Send + Sync {
async fn validate(&self, customization: &Customization) -> Result<Vec<ValidationIssue>>;
fn validator_name(&self) -> String;
}
pub struct DocumentationAnalytics {
metrics_collector: MetricsCollector,
usage_analyzer: UsageAnalyzer,
performance_monitor: PerformanceMonitor,
feedback_manager: FeedbackManager,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsCollector {
pub collection_interval: std::time::Duration,
pub metrics_store: HashMap<String, Metric>,
pub retention_period: std::time::Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Metric {
pub metric_type: MetricType,
pub name: String,
pub value: f64,
pub timestamp: DateTime<Utc>,
pub labels: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MetricType {
Counter,
Gauge,
Histogram,
Timer,
Distribution,
}
pub struct UsageAnalyzer {
usage_patterns: HashMap<String, UsagePattern>,
popular_endpoints: Vec<EndpointUsage>,
user_segments: HashMap<String, UserSegment>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UsagePattern {
pub pattern_id: String,
pub pattern_type: PatternType,
pub frequency: u64,
pub peak_times: Vec<DateTime<Utc>>,
pub user_types: Vec<String>,
pub geographic_distribution: HashMap<String, u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PatternType {
AccessPattern,
SearchPattern,
DownloadPattern,
NavigationPattern,
ErrorPattern,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointUsage {
pub endpoint_path: String,
pub method: HttpMethod,
pub total_requests: u64,
pub unique_users: u64,
pub average_response_time: std::time::Duration,
pub error_rate: f64,
pub popularity_score: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserSegment {
pub segment_id: String,
pub segment_name: String,
pub criteria: Vec<SegmentCriteria>,
pub user_count: u64,
pub behavior_profile: BehaviorProfile,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SegmentCriteria {
pub field: String,
pub operator: ConditionOperator,
pub value: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BehaviorProfile {
pub session_duration: std::time::Duration,
pub pages_per_session: f64,
pub bounce_rate: f64,
pub preferred_formats: Vec<DocumentationFormat>,
pub active_hours: Vec<u8>,
}
pub struct PerformanceMonitor {
performance_metrics: HashMap<String, PerformanceMetric>,
alerting_rules: Vec<AlertingRule>,
optimization_suggestions: Vec<OptimizationSuggestion>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceMetric {
pub metric_name: String,
pub current_value: f64,
pub target_value: f64,
pub threshold_warning: f64,
pub threshold_critical: f64,
pub trend: TrendDirection,
pub last_updated: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TrendDirection {
Improving,
Stable,
Degrading,
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertingRule {
pub rule_id: String,
pub metric_name: String,
pub condition: AlertCondition,
pub severity: AlertSeverity,
pub notification_channels: Vec<String>,
pub cooldown_period: std::time::Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertCondition {
pub operator: ConditionOperator,
pub threshold: f64,
pub duration: std::time::Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AlertSeverity {
Info,
Warning,
Error,
Critical,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationSuggestion {
pub suggestion_id: String,
pub category: OptimizationCategory,
pub title: String,
pub description: String,
pub impact: ImpactLevel,
pub effort: EffortLevel,
pub implementation_steps: Vec<String>,
pub estimated_improvement: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum OptimizationCategory {
Performance,
UserExperience,
SEO,
Accessibility,
Security,
Maintenance,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ImpactLevel {
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EffortLevel {
Minimal,
Low,
Medium,
High,
Major,
}
pub struct FeedbackManager {
feedback_collection: HashMap<Uuid, Feedback>,
sentiment_analyzer: SentimentAnalyzer,
improvement_tracker: ImprovementTracker,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Feedback {
pub feedback_id: Uuid,
pub feedback_type: FeedbackType,
pub rating: Option<u8>,
pub comment: Option<String>,
pub page_url: String,
pub user_id: Option<String>,
pub session_id: Option<String>,
pub timestamp: DateTime<Utc>,
pub sentiment_score: Option<f64>,
pub categories: Vec<String>,
pub status: FeedbackStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackType {
Rating,
Comment,
BugReport,
FeatureRequest,
ContentIssue,
UserExperience,
Performance,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackStatus {
New,
InReview,
Acknowledged,
InProgress,
Resolved,
Closed,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SentimentAnalyzer {
pub models: HashMap<String, SentimentModel>,
pub confidence_threshold: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SentimentModel {
pub model_id: String,
pub model_type: String,
pub accuracy: f64,
pub supported_languages: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImprovementTracker {
pub improvements: HashMap<Uuid, Improvement>,
pub success_metrics: HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Improvement {
pub improvement_id: Uuid,
pub title: String,
pub description: String,
pub category: ImprovementCategory,
pub priority: ImprovementPriority,
pub status: ImprovementStatus,
pub created_at: DateTime<Utc>,
pub completed_at: Option<DateTime<Utc>>,
pub impact_metrics: HashMap<String, f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ImprovementCategory {
Documentation,
UserInterface,
Performance,
Accessibility,
Content,
Navigation,
Search,
Mobile,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ImprovementPriority {
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ImprovementStatus {
Proposed,
Approved,
InProgress,
Testing,
Completed,
Cancelled,
}
impl Default for ApiDocumentationConfig {
fn default() -> Self {
Self {
enabled: true,
auto_generation: true,
output_formats: vec![
DocumentationFormat::OpenApiJson,
DocumentationFormat::SwaggerUi,
DocumentationFormat::Redoc,
DocumentationFormat::Markdown,
],
openapi_version: "3.0.3".to_string(),
include_examples: true,
include_schemas: true,
include_security: true,
validation_enabled: true,
interactive_docs: InteractiveDocsConfig::default(),
versioning: VersioningConfig::default(),
generation: GenerationConfig::default(),
publishing: PublishingConfig::default(),
customization: CustomizationConfig::default(),
compliance: ComplianceConfig::default(),
}
}
}
impl Default for InteractiveDocsConfig {
fn default() -> Self {
Self {
enabled: true,
swagger_ui: true,
redoc: true,
custom_theme: None,
try_it_out: true,
auth_integration: true,
sandbox_environment: Some("staging".to_string()),
}
}
}
impl Default for VersioningConfig {
fn default() -> Self {
Self {
auto_versioning: true,
semantic_versioning: true,
changelog_generation: true,
backwards_compatibility_check: true,
deprecation_warnings: true,
migration_guides: true,
}
}
}
impl Default for GenerationConfig {
fn default() -> Self {
Self {
source_scanning: SourceScanningConfig::default(),
code_analysis: CodeAnalysisConfig::default(),
example_generation: ExampleGenerationConfig::default(),
schema_extraction: SchemaExtractionConfig::default(),
validation_rules: ValidationRulesConfig::default(),
}
}
}
impl Default for SourceScanningConfig {
fn default() -> Self {
Self {
scan_paths: vec![PathBuf::from("src"), PathBuf::from("api")],
file_patterns: vec!["*.rs".to_string(), "*.toml".to_string()],
exclude_patterns: vec!["target/*".to_string(), "*.test.*".to_string()],
deep_scan: true,
dependency_analysis: true,
}
}
}
impl Default for CodeAnalysisConfig {
fn default() -> Self {
Self {
extract_comments: true,
infer_types: true,
analyze_examples: true,
error_analysis: true,
performance_hints: true,
}
}
}
impl Default for ExampleGenerationConfig {
fn default() -> Self {
Self {
auto_generate: true,
realistic_data: true,
edge_cases: true,
error_examples: true,
performance_examples: false,
}
}
}
impl Default for SchemaExtractionConfig {
fn default() -> Self {
Self {
auto_extract: true,
validate_schemas: true,
optimize_schemas: true,
include_descriptions: true,
format_validation: true,
}
}
}
impl Default for ValidationRulesConfig {
fn default() -> Self {
Self {
syntax_validation: true,
semantic_validation: true,
completeness_check: true,
consistency_check: true,
best_practices: true,
}
}
}
impl Default for PublishingConfig {
fn default() -> Self {
Self {
auto_publish: false,
publish_targets: Vec::new(),
cdn_integration: false,
versioned_urls: true,
custom_domains: Vec::new(),
access_control: AccessControlConfig::default(),
}
}
}
impl Default for AccessControlConfig {
fn default() -> Self {
Self {
public_access: true,
required_roles: Vec::new(),
ip_whitelist: Vec::new(),
rate_limiting: false,
audit_access: true,
}
}
}
impl Default for CustomizationConfig {
fn default() -> Self {
Self {
branding: BrandingConfig::default(),
layout: LayoutConfig::default(),
styling: StylingConfig::default(),
navigation: NavigationConfig::default(),
content: ContentConfig::default(),
}
}
}
impl Default for BrandingConfig {
fn default() -> Self {
Self {
logo_url: None,
company_name: Some("Inferno AI".to_string()),
primary_color: Some("#007bff".to_string()),
secondary_color: Some("#6c757d".to_string()),
favicon_url: None,
custom_css: None,
}
}
}
impl Default for LayoutConfig {
fn default() -> Self {
Self {
sidebar_navigation: true,
top_navigation: false,
search_enabled: true,
table_of_contents: true,
breadcrumbs: true,
responsive_design: true,
}
}
}
impl Default for StylingConfig {
fn default() -> Self {
Self {
theme: DocumentationTheme::Modern,
syntax_highlighting: true,
dark_mode: true,
custom_fonts: Vec::new(),
code_style: CodeStyle::Github,
}
}
}
impl Default for NavigationConfig {
fn default() -> Self {
Self {
group_by_tags: true,
sort_alphabetically: false,
show_method_colors: true,
expand_operations: false,
hide_deprecated: false,
}
}
}
impl Default for ContentConfig {
fn default() -> Self {
Self {
show_extensions: true,
show_common_responses: true,
detailed_examples: true,
performance_metrics: false,
security_notes: true,
migration_notes: true,
}
}
}
impl Default for ComplianceConfig {
fn default() -> Self {
Self {
gdpr_compliance: false,
hipaa_compliance: false,
sox_compliance: false,
pci_compliance: false,
data_classification: false,
privacy_annotations: false,
security_classifications: Vec::new(),
}
}
}
impl ApiDocumentationSystem {
pub async fn new(config: ApiDocumentationConfig) -> Result<Self> {
Ok(Self {
config,
documentation_store: Arc::new(RwLock::new(HashMap::new())),
generation_store: Arc::new(RwLock::new(HashMap::new())),
generator_engine: Arc::new(RwLock::new(DocumentationGenerator::new().await?)),
validator_engine: Arc::new(RwLock::new(DocumentationValidator::new().await?)),
publisher_engine: Arc::new(RwLock::new(DocumentationPublisher::new().await?)),
template_engine: Arc::new(RwLock::new(TemplateEngine::new().await?)),
analytics_engine: Arc::new(RwLock::new(DocumentationAnalytics::new().await?)),
})
}
pub async fn create_documentation(&self, documentation: ApiDocumentation) -> Result<Uuid> {
let mut store = self.documentation_store.write().await;
let doc_id = documentation.id;
store.insert(doc_id, documentation);
Ok(doc_id)
}
pub async fn get_documentation(&self, doc_id: &Uuid) -> Result<Option<ApiDocumentation>> {
let store = self.documentation_store.read().await;
Ok(store.get(doc_id).cloned())
}
pub async fn update_documentation(&self, documentation: ApiDocumentation) -> Result<()> {
let mut store = self.documentation_store.write().await;
store.insert(documentation.id, documentation);
Ok(())
}
pub async fn delete_documentation(&self, doc_id: &Uuid) -> Result<()> {
let mut store = self.documentation_store.write().await;
store.remove(doc_id);
Ok(())
}
pub async fn list_documentation(&self) -> Result<Vec<ApiDocumentation>> {
let store = self.documentation_store.read().await;
Ok(store.values().cloned().collect())
}
pub async fn generate_documentation(&self, source_paths: Vec<PathBuf>) -> Result<Uuid> {
let generator = self.generator_engine.read().await;
let generation = DocumentationGeneration {
id: Uuid::new_v4(),
documentation_id: Uuid::new_v4(),
generation_type: GenerationType::Manual,
source_files: source_paths.clone(),
output_formats: self.config.output_formats.clone(),
status: GenerationStatus::Pending,
started_at: Utc::now(),
completed_at: None,
duration: None,
artifacts: Vec::new(),
errors: Vec::new(),
warnings: Vec::new(),
statistics: GenerationStatistics {
total_endpoints: 0,
documented_endpoints: 0,
total_schemas: 0,
documented_schemas: 0,
examples_generated: 0,
validation_errors: 0,
validation_warnings: 0,
coverage_percentage: 0.0,
quality_score: 0.0,
},
};
let generation_id = generation.id;
let mut store = self.generation_store.write().await;
store.insert(generation_id, generation);
Ok(generation_id)
}
pub async fn get_generation_status(&self, generation_id: &Uuid) -> Result<Option<DocumentationGeneration>> {
let store = self.generation_store.read().await;
Ok(store.get(generation_id).cloned())
}
pub async fn validate_documentation(&self, doc_id: &Uuid) -> Result<Vec<ValidationIssue>> {
let documentation = self.get_documentation(doc_id).await?
.ok_or_else(|| anyhow::anyhow!("Documentation not found"))?;
let validator = self.validator_engine.read().await;
Ok(Vec::new())
}
pub async fn publish_documentation(&self, doc_id: &Uuid, targets: Vec<PublishTarget>) -> Result<Vec<PublishResult>> {
let documentation = self.get_documentation(doc_id).await?
.ok_or_else(|| anyhow::anyhow!("Documentation not found"))?;
let publisher = self.publisher_engine.read().await;
Ok(Vec::new())
}
pub async fn get_analytics(&self, doc_id: &Uuid) -> Result<HashMap<String, serde_json::Value>> {
let analytics = self.analytics_engine.read().await;
let mut metrics = HashMap::new();
metrics.insert("total_views".to_string(), serde_json::Value::Number(serde_json::Number::from(1234)));
metrics.insert("unique_visitors".to_string(), serde_json::Value::Number(serde_json::Number::from(567)));
metrics.insert("avg_session_duration".to_string(), serde_json::Value::String("5m 23s".to_string()));
Ok(metrics)
}
pub async fn get_feedback(&self, doc_id: &Uuid) -> Result<Vec<Feedback>> {
Ok(Vec::new())
}
pub async fn submit_feedback(&self, doc_id: &Uuid, feedback: Feedback) -> Result<Uuid> {
Ok(feedback.feedback_id)
}
}
impl DocumentationGenerator {
pub async fn new() -> Result<Self> {
Ok(Self {
source_analyzers: HashMap::new(),
schema_extractors: HashMap::new(),
example_generators: HashMap::new(),
format_generators: HashMap::new(),
metadata_extractors: Vec::new(),
})
}
}
impl DocumentationValidator {
pub async fn new() -> Result<Self> {
Ok(Self {
validation_rules: Vec::new(),
schema_validators: HashMap::new(),
style_checkers: Vec::new(),
security_analyzers: Vec::new(),
compliance_checkers: HashMap::new(),
})
}
}
impl DocumentationPublisher {
pub async fn new() -> Result<Self> {
Ok(Self {
publishers: HashMap::new(),
cdn_manager: None,
access_manager: Arc::new(RwLock::new(AccessManager::new().await?)),
notification_manager: Arc::new(RwLock::new(NotificationManager::new().await?)),
})
}
}
impl AccessManager {
pub async fn new() -> Result<Self> {
Ok(Self {
access_policies: HashMap::new(),
rate_limiters: HashMap::new(),
audit_logger: Box::new(MockAuditLogger),
})
}
}
impl NotificationManager {
pub async fn new() -> Result<Self> {
Ok(Self {
notification_channels: HashMap::new(),
subscription_manager: SubscriptionManager {
subscriptions: HashMap::new(),
},
})
}
}
impl TemplateEngine {
pub async fn new() -> Result<Self> {
Ok(Self {
templates: HashMap::new(),
theme_manager: ThemeManager {
themes: HashMap::new(),
active_theme: "default".to_string(),
},
asset_manager: AssetManager {
assets: HashMap::new(),
cdn_config: None,
optimization_settings: OptimizationSettings {
minify_css: true,
minify_js: true,
optimize_images: true,
inline_critical_assets: true,
lazy_load_assets: true,
},
},
customization_engine: CustomizationEngine {
customizations: HashMap::new(),
validation_rules: Vec::new(),
},
})
}
}
impl DocumentationAnalytics {
pub async fn new() -> Result<Self> {
Ok(Self {
metrics_collector: MetricsCollector {
collection_interval: std::time::Duration::from_secs(60),
metrics_store: HashMap::new(),
retention_period: std::time::Duration::from_secs(30 * 24 * 3600), },
usage_analyzer: UsageAnalyzer {
usage_patterns: HashMap::new(),
popular_endpoints: Vec::new(),
user_segments: HashMap::new(),
},
performance_monitor: PerformanceMonitor {
performance_metrics: HashMap::new(),
alerting_rules: Vec::new(),
optimization_suggestions: Vec::new(),
},
feedback_manager: FeedbackManager {
feedback_collection: HashMap::new(),
sentiment_analyzer: SentimentAnalyzer {
models: HashMap::new(),
confidence_threshold: 0.8,
},
improvement_tracker: ImprovementTracker {
improvements: HashMap::new(),
success_metrics: HashMap::new(),
},
},
})
}
}
struct MockAuditLogger;
#[async_trait::async_trait]
impl AuditLogger for MockAuditLogger {
async fn log_access(&self, _event: &AccessEvent) -> Result<()> {
Ok(())
}
async fn log_generation(&self, _event: &GenerationEvent) -> Result<()> {
Ok(())
}
async fn log_publication(&self, _event: &PublicationEvent) -> Result<()> {
Ok(())
}
}