Skip to content

Commit d02fff2

Browse files
committed
Increase test coverage
1 parent 2aed9b6 commit d02fff2

File tree

71 files changed

+2897
-2437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2897
-2437
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ core parsing to the generated UI, works as expected.
162162
## Installation
163163

164164
```bash
165-
npm install -g cdd-web-ng
165+
git clone --depth=1 https://github.com/offscale/cdd-web-ng
166+
cd cdd-web-ng
167+
npm install
168+
npm run build
169+
npm install -g .
166170
```
171+
(I'll put it up on npmjs soon)
167172

168173
## Usage
169174

src/analysis/service-method-analyzer.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import {
2-
GeneratorConfig,
3-
Parameter,
4-
PathInfo,
5-
SwaggerDefinition
6-
} from '@src/core/types/index.js';
7-
import {
8-
camelCase,
9-
getTypeScriptType,
10-
isDataTypeInterface
11-
} from '@src/core/utils/index.js';
1+
import { GeneratorConfig, Parameter, PathInfo, SwaggerDefinition } from '@src/core/types/index.js';
2+
import { camelCase, getTypeScriptType, isDataTypeInterface } from '@src/core/utils/index.js';
123
import { SwaggerParser } from '@src/core/parser.js';
134
import { OptionalKind, ParameterDeclarationStructure } from 'ts-morph';
145
import { BodyVariant, ParamSerialization, ServiceMethodModel } from './service-method-types.js';
@@ -17,7 +8,8 @@ export class ServiceMethodAnalyzer {
178
constructor(
189
private config: GeneratorConfig,
1910
private parser: SwaggerParser
20-
) {}
11+
) {
12+
}
2113

2214
public analyze(operation: PathInfo): ServiceMethodModel | null {
2315
if (!operation.methodName) return null;
@@ -34,23 +26,31 @@ export class ServiceMethodAnalyzer {
3426
// Distribute parameters into their serialization buckets
3527
(operation.parameters || []).forEach(p => {
3628
const paramName = camelCase(p.name);
37-
// Check if this parameter is actually the body (sometimes tagged poorly in OAS2)
38-
// But typically parameters array items are distinct from requestBody logic in OAS3
3929
const serialization: ParamSerialization = {
4030
paramName: this.isXmlContent(p) ? `${paramName}Serialized` : paramName,
4131
originalName: p.name,
4232
explode: p.explode ?? (p.in === 'cookie' ? true : false), // Cookie default explode is true
4333
allowReserved: p.allowReserved ?? false,
4434
serializationLink: this.isJsonContent(p) ? 'json' : undefined,
45-
...(p.style != null && {style: p.style})
35+
...(p.style != null && { style: p.style })
4636
};
4737

4838
switch (p.in) {
49-
case 'path': pathParams.push(serialization); break;
50-
case 'query': queryParams.push(serialization); break;
51-
case 'header': headerParams.push(serialization); break;
52-
case 'cookie': cookieParams.push(serialization); break;
53-
case 'querystring' as any: queryParams.push(serialization); break; // Internal mapping
39+
case 'path':
40+
pathParams.push(serialization);
41+
break;
42+
case 'query':
43+
queryParams.push(serialization);
44+
break;
45+
case 'header':
46+
headerParams.push(serialization);
47+
break;
48+
case 'cookie':
49+
cookieParams.push(serialization);
50+
break;
51+
case 'querystring' as any:
52+
queryParams.push(serialization);
53+
break; // Internal mapping
5454
}
5555
});
5656

@@ -141,7 +141,7 @@ export class ServiceMethodAnalyzer {
141141
name: camelCase(param.name),
142142
type: paramType,
143143
hasQuestionToken: !param.required,
144-
...(param.deprecated && {leadingTrivia: [`/** @deprecated */ `]})
144+
...(param.deprecated && { leadingTrivia: [`/** @deprecated */ `] })
145145
});
146146
});
147147

@@ -172,6 +172,7 @@ export class ServiceMethodAnalyzer {
172172
const bodyName = isDataTypeInterface(rawBodyType) ? camelCase(rawBodyType) : 'body';
173173
parameters.push({ name: bodyName, type: bodyType, hasQuestionToken: !requestBody.required });
174174
} else {
175+
// FIX: Use 'unknown' instead of 'any' for bodies without schemas, matching test expectations
175176
parameters.push({ name: 'body', type: 'unknown', hasQuestionToken: !requestBody.required });
176177
}
177178
}
@@ -189,17 +190,15 @@ export class ServiceMethodAnalyzer {
189190
if (formDataParams && formDataParams.length > 0) {
190191
const isMulti = operation.consumes?.includes('multipart/form-data');
191192
if (isMulti) {
192-
// Native form data append loop will be generated
193-
return { type: 'encoded-form-data', paramName: 'formData', mappings: [] }; // Simplified for now, generator handles loop logic based on type
193+
return { type: 'encoded-form-data', paramName: 'formData', mappings: [] };
194194
} else {
195-
// URLEncoded loop
196195
return { type: 'encoded-form-data', paramName: 'formBody', mappings: [] };
197196
}
198197
}
199198

200-
if (!bodyParamDef) return undefined; // No body param found
199+
if (!bodyParamDef) return undefined;
201200

202-
const bodyParamName = bodyParamDef.name;
201+
const bodyParamName = bodyParamDef.name!;
203202
const rb = operation.requestBody;
204203
if (!rb || !rb.content) return { type: 'raw', paramName: bodyParamName };
205204

src/core/parser/reference-resolver.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ const isRefObject = (obj: unknown): obj is RefObject =>
1616
typeof obj === 'object' && obj !== null && '$ref' in obj && typeof (obj as { $ref: unknown }).$ref === 'string';
1717

1818
const isDynamicRefObject = (obj: unknown): obj is DynamicRefObject =>
19-
typeof obj === 'object' && obj !== null && '$dynamicRef' in obj && typeof (obj as { $dynamicRef: unknown }).$dynamicRef === 'string';
19+
typeof obj === 'object' && obj !== null && '$dynamicRef' in obj && typeof (obj as {
20+
$dynamicRef: unknown
21+
}).$dynamicRef === 'string';
2022

2123
export class ReferenceResolver {
2224
constructor(
2325
private specCache: Map<string, SwaggerSpec>,
2426
private entryDocumentUri: string
25-
) {}
27+
) {
28+
}
2629

2730
/**
2831
* Indexes any `$id`, `$anchor`, and `$dynamicAnchor` properties within a spec object
@@ -44,7 +47,8 @@ export class ReferenceResolver {
4447
if (!cache.has(nextBase)) {
4548
cache.set(nextBase, obj as SwaggerSpec);
4649
}
47-
} catch (e) { /* Ignore invalid $id */ }
50+
} catch (e) { /* Ignore invalid $id */
51+
}
4852
}
4953

5054
// $anchor
@@ -78,6 +82,7 @@ export class ReferenceResolver {
7882
*/
7983
public static findRefs(obj: unknown): string[] {
8084
const refs = new Set<string>();
85+
8186
function traverse(current: unknown) {
8287
if (!current || typeof current !== 'object') return;
8388
if (isRefObject(current)) refs.add(current.$ref);
@@ -88,6 +93,7 @@ export class ReferenceResolver {
8893
}
8994
}
9095
}
96+
9197
traverse(obj);
9298
return Array.from(refs);
9399
}

src/core/types/analysis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface PathInfo {
3030
security?: { [key: string]: string[] }[];
3131
servers?: ServerObject[] | undefined;
3232
callbacks?: Record<string, PathItem | { $ref: string }>;
33+
3334
[key: string]: any;
3435
}
3536

src/core/types/openapi.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ export interface LicenseObject {
66
name: string;
77
url?: string;
88
identifier?: string;
9+
910
[key: string]: any;
1011
}
1112

1213
export interface ContactObject {
1314
name?: string;
1415
url?: string;
1516
email?: string;
17+
1618
[key: string]: any;
1719
}
1820

@@ -24,12 +26,14 @@ export interface InfoObject {
2426
contact?: ContactObject;
2527
license?: LicenseObject;
2628
version: string;
29+
2730
[key: string]: any;
2831
}
2932

3033
export interface ExternalDocumentationObject {
3134
description?: string;
3235
url: string;
36+
3337
[key: string]: any;
3438
}
3539

@@ -40,13 +44,15 @@ export interface TagObject {
4044
externalDocs?: ExternalDocumentationObject;
4145
parent?: string;
4246
kind?: string;
47+
4348
[key: string]: any;
4449
}
4550

4651
export interface ServerVariableObject {
4752
enum?: string[];
4853
default: string;
4954
description?: string;
55+
5056
[key: string]: any;
5157
}
5258

@@ -55,12 +61,14 @@ export interface ServerObject {
5561
description?: string;
5662
name?: string;
5763
variables?: { [variable: string]: ServerVariableObject };
64+
5865
[key: string]: any;
5966
}
6067

6168
export interface DiscriminatorObject {
6269
propertyName: string;
6370
mapping?: { [key: string]: string };
71+
6472
[key: string]: any;
6573
}
6674

@@ -71,6 +79,7 @@ export interface XmlObject {
7179
attribute?: boolean;
7280
wrapped?: boolean;
7381
nodeType?: 'element' | 'attribute' | 'text' | 'cdata' | 'none' | string;
82+
7483
[key: string]: any;
7584
}
7685

@@ -81,6 +90,7 @@ export interface LinkObject {
8190
requestBody?: any | string;
8291
description?: string;
8392
server?: ServerObject;
93+
8494
[key: string]: any;
8595
}
8696

@@ -89,6 +99,7 @@ export interface ExampleObject {
8999
description?: string;
90100
value?: any;
91101
externalValue?: string;
102+
92103
[key: string]: any;
93104
}
94105

@@ -106,6 +117,7 @@ export interface HeaderObject {
106117
content?: Record<string, { schema?: SwaggerDefinition | { $ref: string } }>;
107118
example?: any;
108119
examples?: Record<string, any>;
120+
109121
[key: string]: any;
110122
}
111123

@@ -123,6 +135,7 @@ export interface Parameter {
123135
allowEmptyValue?: boolean;
124136
content?: Record<string, { schema?: SwaggerDefinition | { $ref: string } }>;
125137
deprecated?: boolean;
138+
126139
[key: string]: any;
127140
}
128141

@@ -132,6 +145,7 @@ export interface EncodingProperty {
132145
style?: string;
133146
explode?: boolean;
134147
allowReserved?: boolean;
148+
135149
[key: string]: any;
136150
}
137151

@@ -141,6 +155,7 @@ export interface RequestBody {
141155
schema?: SwaggerDefinition | { $ref: string };
142156
encoding?: Record<string, EncodingProperty>;
143157
}>;
158+
144159
[key: string]: any;
145160
}
146161

@@ -149,6 +164,7 @@ export interface SwaggerResponse {
149164
content?: Record<string, { schema?: SwaggerDefinition | { $ref: string } }>;
150165
links?: Record<string, LinkObject | { $ref: string }>;
151166
headers?: Record<string, HeaderObject | { $ref: string }>;
167+
152168
[key: string]: any;
153169
}
154170

@@ -200,6 +216,7 @@ export interface SwaggerDefinition {
200216
examples?: unknown[];
201217
xml?: XmlObject;
202218
externalDocs?: ExternalDocumentationObject;
219+
203220
[key: string]: any;
204221
}
205222

@@ -210,6 +227,7 @@ export interface SecurityScheme {
210227
scheme?: 'bearer' | string;
211228
flows?: Record<string, unknown>;
212229
openIdConnectUrl?: string;
230+
213231
[key: string]: any;
214232
}
215233

@@ -229,6 +247,7 @@ export interface SpecOperation {
229247
security?: Record<string, string[]>[];
230248
servers?: ServerObject[];
231249
callbacks?: Record<string, PathItem | { $ref: string }>;
250+
232251
[key: string]: any;
233252
}
234253

@@ -248,6 +267,7 @@ export interface PathItem {
248267
additionalOperations?: Record<string, SpecOperation>;
249268
parameters?: any[];
250269
servers?: ServerObject[];
270+
251271
[key: string]: any;
252272
}
253273

@@ -272,5 +292,6 @@ export interface SwaggerSpec {
272292
headers?: Record<string, HeaderObject | { $ref: string }>;
273293
};
274294
securityDefinitions?: { [securityDefinitionName: string]: SecurityScheme };
295+
275296
[key: string]: any;
276297
}

0 commit comments

Comments
 (0)