swagger_generator_flutter/generator_config.yaml

248 lines
5.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Augment 代码生成器配置文件
# 基于 OpenAPI 3.0 标准的配置规范
# 基本配置
generator:
name: "xy_swagger_generator"
version: "2.0"
author: "max"
copyright: "Copyright (C) 2025 YuanXuan. All rights reserved."
# 输入配置
input:
# Swagger 文档源
swagger_url: "http://localhost:5000/swagger/v1/swagger.json"
swagger_file: "./swagger.json"
# 验证配置
validate_schema: true
strict_mode: true
# 输出配置
output:
# 输出目录
base_dir: "./generator"
api_dir: "./generator/api"
models_dir: "./generator/api_models"
# 文件命名
api_file_suffix: "_api.dart"
model_file_suffix: ".dart"
# 是否按 tag 分组
split_by_tags: true
# 代码生成配置
generation:
# API 接口配置
api:
enabled: true
use_retrofit: true
use_dio: true
parser: "JsonSerializable"
# 基础类型配置
base_result_type: "BaseResult"
base_page_result_type: "BasePageResult"
base_result_import: "package:learning_officer_oa/common/models/common/base_result.dart"
base_page_result_import: "package:learning_officer_oa/common/models/common/base_page_result.dart"
# 方法命名
method_naming: "camelCase" # camelCase, snake_case
# 数据模型配置
models:
enabled: true
use_json_serializable: true
# JsonSerializable 配置
json_serializable:
checked: true
include_if_null: false
explicit_to_json: true
# 类命名
class_naming: "PascalCase" # PascalCase, snake_case
field_naming: "camelCase" # camelCase, snake_case
# 构造函数配置
use_const_constructor: true
required_for_non_nullable: true
# 类型映射配置
type_mapping:
# OpenAPI -> Dart 类型映射
string: "String"
integer: "int"
number: "double"
boolean: "bool"
array: "List"
object: "Map<String, dynamic>"
# 特殊类型处理
date: "DateTime"
date-time: "DateTime"
binary: "Uint8List"
# 自定义类型映射
custom_types:
# 示例:特定格式的字符串映射到自定义类型
# "uuid": "Uuid"
# "email": "EmailAddress"
# 导入管理配置
imports:
# 按需导入
on_demand: true
# 自动排序
auto_sort: true
# 分组导入
group_imports: true
# 标准库导入
dart_imports:
- "dart:convert"
- "dart:typed_data"
# 第三方库导入
package_imports:
- "package:dio/dio.dart"
- "package:retrofit/retrofit.dart"
- "package:json_annotation/json_annotation.dart"
# 验证配置
validation:
# 严格模式
strict_mode: true
# 检查项
checks:
- "schema_exists" # 检查 schema 是否存在
- "ref_resolution" # 检查 $ref 引用
- "type_consistency" # 检查类型一致性
- "nullable_correctness" # 检查可空性正确性
- "required_fields" # 检查必需字段
# 错误处理
on_error: "warn" # fail, warn, ignore
# 警告处理
on_warning: "log" # fail, log, ignore
# 优化配置
optimization:
# 代码优化
remove_unused_imports: true
optimize_imports: true
# 性能优化
cache_schemas: true
parallel_generation: false
# 内存优化
lazy_loading: true
# 调试配置
debug:
# 详细日志
verbose: false
# 调试输出
debug_output: false
# 性能监控
performance_monitoring: false
# 生成统计
generation_stats: true
# 兼容性配置
compatibility:
# Dart 版本
dart_version: ">=3.0.0"
# Flutter 版本
flutter_version: ">=3.10.0"
# 依赖版本
dependencies:
dio: "^5.0.0"
retrofit: "^4.0.0"
json_annotation: "^4.8.0"
dev_dependencies:
build_runner: "^2.3.0"
retrofit_generator: "^8.0.0"
json_serializable: "^6.6.0"
# 自定义配置
custom:
# 项目特定配置
project_name: "learning_officer_oa"
# 特殊处理规则
special_handling:
# 健康检查接口返回 void
health_check_paths:
- "/health"
- "/healthcheck"
- "/api/health"
# 分页接口参数名
pagination_params:
- "page"
- "size"
- "limit"
- "offset"
- "pageIndex"
- "pageSize"
# 忽略的路径
ignored_paths:
- "/swagger"
- "/docs"
# 忽略的 tags
ignored_tags:
- "Internal"
- "Debug"
# 模板配置
templates:
# 文件头模板
# 支持模板变量:
# {fileName} - 文件名(如 "user_api.dart"
# {fileType} - 文件类型描述(如 "API 接口定义"、"模型定义"
# {swaggerUrl} - Swagger 文档 URL
# {generatorName} - 生成器名称(从 generator.name 读取)
# {author} - 作者(从 generator.author 读取)
# {copyright} - 版权信息(从 generator.copyright 读取)
file_header: |
// {fileType}
// 基于 Swagger API 文档: {swaggerUrl}
// 由 {generatorName} by {author} 生成
// {copyright}
# API 类模板
api_class: |
/// {tagName} API 接口
/// 负责处理 {tagName} 相关的接口
@RestApi(parser: Parser.JsonSerializable)
abstract class {className} {
factory {className}(Dio dio, {String? baseUrl}) = _{className};
}
# 模型类模板
model_class: |
@JsonSerializable(checked: true, includeIfNull: false)
class {className} {
const {className}({constructorParams});
factory {className}.fromJson(Map<String, dynamic> json) =>
_${className}FromJson(json);
Map<String, dynamic> toJson() => _${className}ToJson(this);
}