51 lines
1.5 KiB
Dart
51 lines
1.5 KiB
Dart
/// API naming utilities for endpoint and controller name generation
|
|
library;
|
|
|
|
import 'package:swagger_generator_flutter/core/models.dart';
|
|
import 'package:swagger_generator_flutter/utils/string_utils/naming_converter.dart';
|
|
|
|
/// API naming utilities
|
|
class ApiNamingUtils {
|
|
/// Generate endpoint name from path and operationId
|
|
static String generateEndpointName(String path, String? operationId) {
|
|
// If operationId exists, use it with priority
|
|
if (operationId != null && operationId.isNotEmpty) {
|
|
return NamingConverter.toCamelCase(operationId);
|
|
}
|
|
|
|
// Remove version prefix from path
|
|
var cleanPath = path.replaceFirst('/api/v1', '');
|
|
|
|
// Remove leading slash
|
|
if (cleanPath.startsWith('/')) {
|
|
cleanPath = cleanPath.substring(1);
|
|
}
|
|
|
|
// Convert path to camelCase
|
|
final parts = cleanPath.split('/');
|
|
if (parts.length >= 2) {
|
|
final controller = parts[0];
|
|
final action = parts[1];
|
|
return NamingConverter.toCamelCase('${controller}_$action');
|
|
}
|
|
|
|
return NamingConverter.toCamelCase(cleanPath.replaceAll('/', '_'));
|
|
}
|
|
|
|
/// Extract controller name from API path
|
|
static String extractControllerName(ApiPath path) {
|
|
// Extract controller name from tags
|
|
if (path.tags.isNotEmpty) {
|
|
return path.tags.first;
|
|
}
|
|
|
|
// Extract controller name from path
|
|
final pathParts = path.path.split('/');
|
|
if (pathParts.length > 1) {
|
|
return NamingConverter.toPascalCase(pathParts[1]);
|
|
}
|
|
|
|
return 'General';
|
|
}
|
|
}
|