Skip to content

Commit 6962ddd

Browse files
committed
[src/core/types.ts,src/service/emit/test/service-test.generator.ts] typedoc fixes
1 parent 2b8f6b0 commit 6962ddd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/core/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export interface SwaggerDefinition {
117117
writeOnly?: boolean;
118118
nullable?: boolean;
119119
required?: string[];
120+
/** An example of the schema representation. */
121+
example?: unknown; // FIX: Added the 'example' property.
120122
}
121123

122124
/** Represents a security scheme recognized by the API. */

src/service/emit/test/service-test.generator.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22
import { Project, SourceFile } from 'ts-morph';
33
import { SwaggerParser } from '../../../core/parser.js';
4-
import { GeneratorConfig, PathInfo } from '../../../core/types.js';
4+
import { GeneratorConfig, PathInfo, SwaggerDefinition } from '../../../core/types.js';
55
import {
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

Comments
 (0)