11import * as path from 'path' ;
22import { Project , SourceFile } from 'ts-morph' ;
33import { SwaggerParser } from '../../../core/parser.js' ;
4- import { GeneratorConfig , PathInfo } from '../../../core/types.js' ;
4+ import { GeneratorConfig , PathInfo , SwaggerDefinition } from '../../../core/types.js' ;
55import {
66 camelCase ,
77 pascalCase ,
@@ -87,10 +87,15 @@ export class ServiceTestGenerator {
8787 if ( ! op . methodName ) continue ;
8888
8989 const { responseModel, responseType, bodyModel } = this . getMethodTypes ( op ) ;
90- const params = op . parameters ?. map ( p => ( {
91- name : camelCase ( p . name ) ,
92- value : typeof p . schema ?. type === 'number' ? '123' : `'test-${ p . name } '` ,
93- } ) ) ?? [ ] ;
90+ const params = op . parameters ?. map ( p => {
91+ // FIX: Check the 'type' property safely by casting.
92+ const schema = p . schema as SwaggerDefinition ;
93+ const isNumeric = schema ?. type === 'number' || schema ?. type === 'integer' ;
94+ return {
95+ name : camelCase ( p . name ) ,
96+ value : isNumeric ? '123' : `'test-${ p . name } '` ,
97+ } ;
98+ } ) ?? [ ] ;
9499 const bodyParam = op . requestBody ?. content ?. [ 'application/json' ]
95100 ? { name : bodyModel ? camelCase ( bodyModel ) : 'body' , model : bodyModel }
96101 : null ;
@@ -106,7 +111,6 @@ export class ServiceTestGenerator {
106111 tests . push ( ` it('should return ${ responseType } on success', () => {` ) ;
107112 if ( responseModel ) {
108113 const singleMock = this . mockDataGenerator . generate ( responseModel ) ;
109- // FIX: Check if the full response type is an array and wrap the mock data accordingly.
110114 const isArray = responseType . endsWith ( '[]' ) ;
111115 const mockResponse = isArray ? `[${ singleMock } ]` : singleMock ;
112116 tests . push ( ` const mockResponse: ${ responseType } = ${ mockResponse } ;` ) ;
0 commit comments