98 lines
3.3 KiB
Dart
98 lines
3.3 KiB
Dart
import 'package:swagger_generator_flutter/core/config_repository.dart';
|
||
|
||
/// Swagger配置管理
|
||
/// 集中管理所有Swagger相关的配置项
|
||
/// 支持从 generator_config.yaml 文件读取配置
|
||
class SwaggerConfig {
|
||
/// 默认 Swagger JSON 文档 URLs(当配置文件不存在时使用)
|
||
static const List<String> defaultSwaggerJsonUrls = [
|
||
// 'https://quanxue-test-api.w.23544.com:8843/swagger/v1/swagger.json',
|
||
'https://quanxue-test-api.w.23544.com:8843/swagger/v2/swagger.json',
|
||
];
|
||
|
||
/// Swagger JSON 文档 URLs(支持多版本)
|
||
/// 优先从配置文件读取,如果配置文件不存在则使用默认值
|
||
static List<String> get swaggerJsonUrls {
|
||
// Keep public API but delegate to ConfigRepository
|
||
final config = ConfigRepository.loadSync();
|
||
return config.swaggerUrls;
|
||
}
|
||
|
||
/// 基础API URL
|
||
static const String baseUrl = 'http://192.168.2.7:17288';
|
||
|
||
/// API版本
|
||
static const String apiVersion = '/api/v1';
|
||
|
||
/// 默认生成器输出目录
|
||
static const String defaultGeneratorDir = 'generator';
|
||
|
||
/// 默认API文件目录
|
||
static const String defaultApiDir = 'api';
|
||
|
||
/// 默认模型文件目录
|
||
static const String defaultModelsDir = 'api_models';
|
||
|
||
/// 获取生成器输出目录(从配置文件读取)
|
||
static String get generatorDir => ConfigRepository.loadSync().baseDir;
|
||
|
||
/// 获取API文件目录(从配置文件读取)
|
||
static String get apiDir => ConfigRepository.loadSync().apiDir;
|
||
|
||
/// 获取模型文件目录(从配置文件读取)
|
||
static String get modelsDir => ConfigRepository.loadSync().modelsDir;
|
||
|
||
/// 获取 BaseResult 导入路径(从配置文件读取)
|
||
static String get baseResultImport =>
|
||
ConfigRepository.loadSync().baseResultImport;
|
||
|
||
/// 获取 BasePageResult 导入路径(从配置文件读取)
|
||
static String get basePageResultImport =>
|
||
ConfigRepository.loadSync().basePageResultImport;
|
||
|
||
/// 获取枚举键名映射配置(从配置文件读取)
|
||
static Map<String, Map<dynamic, EnumKeyMapping>>? get enumKeyMappings =>
|
||
ConfigRepository.loadSync().enumKeyMappings;
|
||
|
||
/// 获取 JsonSerializable 配置(从配置文件读取)
|
||
static JsonSerializableConfig? get jsonSerializableConfig =>
|
||
ConfigRepository.loadSync().jsonSerializableConfig;
|
||
|
||
/// 默认文档文件名
|
||
static const String defaultDocumentationFile =
|
||
'generated_api_documentation.md';
|
||
|
||
/// HTTP请求头配置
|
||
static const Map<String, String> httpHeaders = {
|
||
'Accept': 'application/json',
|
||
'User-Agent': 'Flutter-SwaggerParser/1.0',
|
||
};
|
||
|
||
/// 生成选项配置
|
||
static const Map<String, dynamic> defaultGenerateOptions = {
|
||
'generateModels': true,
|
||
'generateDocs': true,
|
||
'generateApi': true,
|
||
'useSimpleModels': false,
|
||
'separateModelFiles': true,
|
||
};
|
||
|
||
/// 获取完整的API基础URL
|
||
static String get fullApiUrl => '$baseUrl$apiVersion';
|
||
|
||
/// 获取控制器描述
|
||
/// 优先使用Swagger文档中的描述,否则使用控制器名称
|
||
static String getControllerDescription(
|
||
String controllerName, {
|
||
String? swaggerDescription,
|
||
}) {
|
||
// 1. 使用Swagger文档中的描述
|
||
if (swaggerDescription != null && swaggerDescription.isNotEmpty) {
|
||
return swaggerDescription;
|
||
}
|
||
|
||
// 2. 使用控制器名称
|
||
return controllerName;
|
||
}
|
||
}
|