fix: enhance DTO generation, schema validation, and formatting logic #71
@@ -3,7 +3,7 @@ import path from 'path';
|
|||||||
import mustache from 'mustache';
|
import mustache from 'mustache';
|
||||||
import { logStep, logSuccess, logDetail } from '../utils/logger';
|
import { logStep, logSuccess, logDetail } from '../utils/logger';
|
||||||
import { mapSwaggerTypeToTs } from '../utils/type-mapper';
|
import { mapSwaggerTypeToTs } from '../utils/type-mapper';
|
||||||
import { toCamelCase } from '../utils/name-formatter';
|
import { toCamelCase, toPascalCase } from '../utils/name-formatter';
|
||||||
import { resolveMockValue } from '../utils/mock-value-resolver';
|
import { resolveMockValue } from '../utils/mock-value-resolver';
|
||||||
import type {
|
import type {
|
||||||
SwaggerAnalysis,
|
SwaggerAnalysis,
|
||||||
@@ -362,7 +362,7 @@ export function generateCleanArchitecture(
|
|||||||
apis: [
|
apis: [
|
||||||
{
|
{
|
||||||
operations: {
|
operations: {
|
||||||
classname: tag,
|
classname: toPascalCase(tag),
|
||||||
classFilename: toCamelCase(tag),
|
classFilename: toCamelCase(tag),
|
||||||
classVarName: toCamelCase(tag),
|
classVarName: toCamelCase(tag),
|
||||||
constantName: tag.toUpperCase().replace(/[^A-Z0-9]/g, '_'),
|
constantName: tag.toUpperCase().replace(/[^A-Z0-9]/g, '_'),
|
||||||
|
|||||||
@@ -1,12 +1,31 @@
|
|||||||
/**
|
/**
|
||||||
* Converts a PascalCase name to camelCase by lowercasing the first character.
|
* Converts a string to PascalCase, handling spaces, hyphens and underscores.
|
||||||
|
* Used to derive class names from schema/tag names.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* toPascalCase('Product Format') // 'ProductFormat'
|
||||||
|
* toPascalCase('user-response') // 'UserResponse'
|
||||||
|
* toPascalCase('UserSchema') // 'UserSchema'
|
||||||
|
*/
|
||||||
|
export function toPascalCase(name: string): string {
|
||||||
|
if (!name) return name;
|
||||||
|
return name
|
||||||
|
.split(/[\s\-_]+/)
|
||||||
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
|
.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string to camelCase, handling spaces, hyphens and underscores.
|
||||||
* Used to derive class filenames and variable names from schema/tag names.
|
* Used to derive class filenames and variable names from schema/tag names.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* toCamelCase('Product Format') // 'productFormat'
|
||||||
* toCamelCase('ProductResponse') // 'productResponse'
|
* toCamelCase('ProductResponse') // 'productResponse'
|
||||||
* toCamelCase('UserSchema') // 'userSchema'
|
* toCamelCase('UserSchema') // 'userSchema'
|
||||||
*/
|
*/
|
||||||
export function toCamelCase(name: string): string {
|
export function toCamelCase(name: string): string {
|
||||||
if (!name) return name;
|
if (!name) return name;
|
||||||
return name.charAt(0).toLowerCase() + name.slice(1);
|
const pascal = toPascalCase(name);
|
||||||
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user