Compare commits
No commits in common. "88deff67b6593b819c721953976a6751f0495f03" and "be0e15178ffb08144c39d8bdac0695f5272c862c" have entirely different histories.
88deff67b6
...
be0e15178f
|
|
@ -2,13 +2,6 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## [3.2.1] - 2026-01-12
|
|
||||||
|
|
||||||
### 🐛 修复
|
|
||||||
|
|
||||||
#### 模型类名前缀逻辑修复
|
|
||||||
- ✅ **强制添加前缀**:修复了当类名已包含前缀时不重复添加前缀的逻辑,确保 `SubjectInfo` 配置前缀 `S` 后生成 `SSubjectInfo`。
|
|
||||||
- ✅ **测试接口暴露**:为 `ConfigRepository` 添加 `setCachedConfig` 接口以便于测试。
|
|
||||||
## [3.2.0] - 2026-01-12
|
## [3.2.0] - 2026-01-12
|
||||||
|
|
||||||
### 🎉 新特性
|
### 🎉 新特性
|
||||||
|
|
|
||||||
|
|
@ -66,11 +66,6 @@ class ConfigRepository {
|
||||||
|
|
||||||
static ConfigRepository? _cachedConfig;
|
static ConfigRepository? _cachedConfig;
|
||||||
|
|
||||||
/// 设置缓存配置(仅用于测试)
|
|
||||||
static void setCachedConfig(ConfigRepository config) {
|
|
||||||
_cachedConfig = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 同步加载配置(用于向后兼容或必须同步的场景)
|
/// 同步加载配置(用于向后兼容或必须同步的场景)
|
||||||
/// 为默认配置路径启用缓存
|
/// 为默认配置路径启用缓存
|
||||||
static ConfigRepository loadSync([String? configPath]) {
|
static ConfigRepository loadSync([String? configPath]) {
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,10 @@ class StringHelper {
|
||||||
var className = NamingConverter.generateClassName(name);
|
var className = NamingConverter.generateClassName(name);
|
||||||
final prefix = SwaggerConfig.modelClassPrefix;
|
final prefix = SwaggerConfig.modelClassPrefix;
|
||||||
if (prefix != null && prefix.isNotEmpty) {
|
if (prefix != null && prefix.isNotEmpty) {
|
||||||
|
if (!className.startsWith(prefix)) {
|
||||||
className = prefix + className;
|
className = prefix + className;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return className;
|
return className;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
name: swagger_generator_flutter
|
name: swagger_generator_flutter
|
||||||
description: A powerful Swagger/OpenAPI code generator for Flutter projects with Dio + Retrofit support
|
description: A powerful Swagger/OpenAPI code generator for Flutter projects with Dio + Retrofit support
|
||||||
|
|
||||||
version: 3.2.1
|
version: 3.2.0
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=3.0.0 <4.0.0'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:swagger_generator_flutter/core/config.dart';
|
||||||
import 'package:swagger_generator_flutter/core/config_repository.dart';
|
import 'package:swagger_generator_flutter/core/config_repository.dart';
|
||||||
import 'package:swagger_generator_flutter/utils/string_helper.dart';
|
import 'package:swagger_generator_flutter/utils/string_helper.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
@ -46,49 +47,6 @@ generator:
|
||||||
expect(config.modelClassPrefix, isNull);
|
expect(config.modelClassPrefix, isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should apply class_prefix using StringHelper.generateClassName', () {
|
|
||||||
configFile.writeAsStringSync('''
|
|
||||||
generator:
|
|
||||||
name: test
|
|
||||||
|
|
||||||
output:
|
|
||||||
models:
|
|
||||||
class_prefix: "S"
|
|
||||||
|
|
||||||
generation:
|
|
||||||
models:
|
|
||||||
class_prefix: "S"
|
|
||||||
''');
|
|
||||||
|
|
||||||
// Reload config to ensure StringHelper picks up the new prefix
|
|
||||||
// This relies on SwaggerConfig.modelClassPrefix internally calling ConfigRepository.loadSync()
|
|
||||||
// which will find the config file in the current working directory (or tempDir in this test context).
|
|
||||||
// For this test to work, the test runner's CWD must be tempDir, or PathResolver must be mocked.
|
|
||||||
// Assuming PathResolver.findConfigFile() correctly finds the temp file.
|
|
||||||
|
|
||||||
// The current implementation of StringHelper.generateClassName relies on SwaggerConfig.modelClassPrefix
|
|
||||||
// which in turn calls ConfigRepository.loadSync() without arguments.
|
|
||||||
// This means it will try to find the config file in the current working directory or via PathResolver.
|
|
||||||
// For this test to pass, the `configFile` must be discoverable by `ConfigRepository.loadSync()`.
|
|
||||||
// This test implicitly relies on the test environment's CWD or PathResolver setup.
|
|
||||||
|
|
||||||
// To make this test robust, StringHelper should ideally take a Config object or
|
|
||||||
// SwaggerConfig should have a way to inject a test config.
|
|
||||||
// For now, we proceed with the assumption that `ConfigRepository.loadSync()` will find `configFile`.
|
|
||||||
|
|
||||||
// Force a reload of the static config by accessing it.
|
|
||||||
// This is a bit of a hack due to the static nature of SwaggerConfig and StringHelper.
|
|
||||||
// A better approach would be to pass the config explicitly or mock the static dependencies.
|
|
||||||
// Load config and set it as cached so static accessors pick it up
|
|
||||||
final config = ConfigRepository.loadSync(configFile.path);
|
|
||||||
ConfigRepository.setCachedConfig(config);
|
|
||||||
|
|
||||||
expect(StringHelper.generateClassName('User'), 'SUser');
|
|
||||||
expect(StringHelper.generateClassName('model'), 'SModel');
|
|
||||||
// Test case: prefix is 'S' and name starts with 'S'
|
|
||||||
expect(StringHelper.generateClassName('SubjectInfo'), 'SSubjectInfo');
|
|
||||||
});
|
|
||||||
|
|
||||||
// NOTE: Testing StringHelper.generateClassName directly implies checking if it reads from the GLOBAL config.
|
// NOTE: Testing StringHelper.generateClassName directly implies checking if it reads from the GLOBAL config.
|
||||||
// However, ConfigRepository.loadSync() creates an instance, but SwaggerConfig accessors call ConfigRepository.loadSync() individually.
|
// However, ConfigRepository.loadSync() creates an instance, but SwaggerConfig accessors call ConfigRepository.loadSync() individually.
|
||||||
// Since ConfigRepository.loadSync() without args looks for default file, we need a way to inject the config or point it to our file.
|
// Since ConfigRepository.loadSync() without args looks for default file, we need a way to inject the config or point it to our file.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue