Skip to content

Commit dfcb461

Browse files
committed
[package-lock.json] Regenerate ; [*.ts] Reformat ; get typedoc and build to succeed
1 parent 89c1d7d commit dfcb461

File tree

8 files changed

+314
-291
lines changed

8 files changed

+314
-291
lines changed

package-lock.json

Lines changed: 241 additions & 261 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/parser.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* parsing, and providing a unified interface to OpenAPI (3.x) and Swagger (2.x) specifications.
55
*/
66

7-
import { GeneratorConfig, PathInfo, SecurityScheme, ServerObject, SwaggerDefinition, SwaggerSpec, LinkObject } from './types.js';
7+
import {
8+
GeneratorConfig,
9+
LinkObject,
10+
PathInfo,
11+
SecurityScheme,
12+
ServerObject,
13+
SwaggerDefinition,
14+
SwaggerSpec
15+
} from './types.js';
816
import * as fs from 'node:fs';
917
import * as path from 'node:path';
1018
import { pathToFileURL } from 'node:url';

src/core/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ export interface PathInfo {
236236
/** Security requirements specific to this operation. keys are definitions, values are scopes. */
237237
security?: { [key: string]: string[] }[];
238238
/** An alternate server array to service this operation. (OAS 3+) */
239-
servers?: ServerObject[];
239+
servers?: ServerObject[] | undefined; // Allow undefined explicit assignment
240240
/** A map of possible out-of band callbacks related to the parent operation. (OAS 3+) */
241-
callbacks?: Record<string, PathItem | { $ref: string }>;
241+
callbacks?: Record<string, PathItem | { $ref: string }> | undefined; // Allow undefined explicit assignment
242242
}
243243

244244
/** A single encoding definition for a multipart property. */

src/core/utils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111
import { MethodDeclaration } from 'ts-morph';
1212
import {
1313
GeneratorConfig,
14+
HeaderObject,
1415
Parameter,
1516
PathInfo,
1617
PathItem,
1718
RequestBody,
1819
SpecOperation,
1920
SwaggerDefinition,
20-
SwaggerResponse,
21-
HeaderObject
21+
SwaggerResponse
2222
} from './types.js';
23-
import {
24-
BodyParameter,
25-
Parameter as SwaggerOfficialParameter,
26-
Response
27-
} from "swagger-schema-official";
23+
import { BodyParameter, Parameter as SwaggerOfficialParameter, Response } from "swagger-schema-official";
2824

2925
// Re-export runtime expressions
3026
export * from './runtime-expressions.js';

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
MethodDeclarationOverloadStructure,
44
OptionalKind,
55
ParameterDeclarationStructure,
6+
WriterFunction,
67
} from 'ts-morph';
7-
import { GeneratorConfig, Parameter, PathInfo, SwaggerDefinition } from '../../../core/types.js';
8-
import { camelCase, getTypeScriptType, isDataTypeInterface, pascalCase } from '../../../core/utils.js';
8+
import { GeneratorConfig, Parameter, PathInfo, SwaggerDefinition } from '@src/core/types.js';
9+
import { camelCase, getTypeScriptType, isDataTypeInterface } from '@src/core/utils.js';
910
import { HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
1011
import { SwaggerParser } from "@src/core/parser.js";
1112

@@ -101,8 +102,8 @@ export class ServiceMethodGenerator {
101102
name: paramName,
102103
type: paramType,
103104
hasQuestionToken: !param.required,
104-
// ParameterDeclarationStructure does not support 'docs', so we use leadingTrivia to inject JSDoc
105-
leadingTrivia: param.deprecated ? [`/** @deprecated */ `] : undefined
105+
// Cast undefined to satisfy strict exactOptionalPropertyTypes
106+
leadingTrivia: param.deprecated ? [`/** @deprecated */ `] : (undefined as unknown as string | WriterFunction | (string | WriterFunction)[])
106107
});
107108
});
108109
const requestBody = operation.requestBody;
@@ -357,17 +358,29 @@ export class ServiceMethodGenerator {
357358

358359
return [
359360
{
360-
parameters: [...parameters, { name: 'options', hasQuestionToken: true, type: `RequestOptions & { observe?: 'body' }` }],
361+
parameters: [...parameters, {
362+
name: 'options',
363+
hasQuestionToken: true,
364+
type: `RequestOptions & { observe?: 'body' }`
365+
}],
361366
returnType: `Observable<${finalResponseType}>`,
362367
docs: [`${methodName}. \n${paramsDocs}\n@param options The options for this request.${deprecationDoc}`]
363368
},
364369
{
365-
parameters: [...parameters, { name: 'options', hasQuestionToken: false, type: `RequestOptions & { observe: 'response' }` }],
370+
parameters: [...parameters, {
371+
name: 'options',
372+
hasQuestionToken: false,
373+
type: `RequestOptions & { observe: 'response' }`
374+
}],
366375
returnType: `Observable<HttpResponse<${finalResponseType}>>`,
367376
docs: [`${methodName}. \n${paramsDocs}\n@param options The options for this request, with response observation enabled.${deprecationDoc}`]
368377
},
369378
{
370-
parameters: [...parameters, { name: 'options', hasQuestionToken: false, type: `RequestOptions & { observe: 'events' }` }],
379+
parameters: [...parameters, {
380+
name: 'options',
381+
hasQuestionToken: false,
382+
type: `RequestOptions & { observe: 'events' }`
383+
}],
371384
returnType: `Observable<HttpEvent<${finalResponseType}>>`,
372385
docs: [`${methodName}. \n${paramsDocs}\n@param options The options for this request, with event observation enabled.${deprecationDoc}`]
373386
}

src/service/emit/type/type.generator.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import * as path from "node:path";
2-
import { Project, SourceFile, JSDocStructure, JSDocTagStructure, OptionalKind, PropertySignatureStructure, WriterFunction } from "ts-morph";
3-
import { GeneratorConfig, SwaggerDefinition, PathItem, LinkObject, HeaderObject } from "../../../core/types.js";
4-
import { SwaggerParser } from "../../../core/parser.js";
5-
import { extractPaths, getTypeScriptType, pascalCase } from "../../../core/utils.js";
2+
import {
3+
JSDocStructure,
4+
JSDocTagStructure,
5+
OptionalKind,
6+
Project,
7+
PropertySignatureStructure,
8+
SourceFile
9+
} from "ts-morph";
10+
import { GeneratorConfig, HeaderObject, PathItem, SwaggerDefinition } from "@src/core/types.js";
11+
import { SwaggerParser } from "@src/core/parser.js";
12+
import { extractPaths, getTypeScriptType, pascalCase } from "@src/core/utils.js";
613

714
export class TypeGenerator {
815
constructor(
916
private parser: SwaggerParser,
1017
private project: Project,
1118
private config: GeneratorConfig
12-
) { }
19+
) {
20+
}
1321

1422
public generate(outputDir: string): void {
1523
const modelsDir = path.join(outputDir, "models");
@@ -92,7 +100,10 @@ export class TypeGenerator {
92100
properties: properties,
93101
docs: [{
94102
description: `Parameters for the '${linkName}' link.`,
95-
tags: [{ tagName: 'see', text: 'https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#linkObject' }]
103+
tags: [{
104+
tagName: 'see',
105+
text: 'https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#linkObject'
106+
}]
96107
}]
97108
});
98109
}
@@ -101,7 +112,7 @@ export class TypeGenerator {
101112
// 5. Response Headers
102113
allPaths.forEach(op => {
103114
if (op.responses) {
104-
Object. entries(op.responses).forEach(([code, resp]) => {
115+
Object.entries(op.responses).forEach(([code, resp]) => {
105116
if (resp.headers) {
106117
// Naming: OperationId + Code + Headers, e.g., GetUser200Headers
107118
const opIdBase = op.operationId ? pascalCase(op.operationId) : pascalCase(op.method + op.path);
@@ -220,14 +231,20 @@ export class TypeGenerator {
220231
name: `${modelName}Request`,
221232
isExported: true,
222233
properties: requestProps,
223-
docs: this.buildJSDoc({ ...def, description: `Model for sending ${modelName} data (excludes read-only fields).` })
234+
docs: this.buildJSDoc({
235+
...def,
236+
description: `Model for sending ${modelName} data (excludes read-only fields).`
237+
})
224238
});
225239
this.applyComposition(requestDecl, def, { excludeReadOnly: true });
226240
this.applyIndexSignature(requestDecl, def);
227241
}
228242
}
229243

230-
private applyComposition(interfaceDecl: any, def: SwaggerDefinition, options: { excludeReadOnly?: boolean, excludeWriteOnly?: boolean }): void {
244+
private applyComposition(interfaceDecl: any, def: SwaggerDefinition, options: {
245+
excludeReadOnly?: boolean,
246+
excludeWriteOnly?: boolean
247+
}): void {
231248
if (def.allOf) {
232249
const extendsTypes: string[] = [];
233250
def.allOf.forEach(sub => {
@@ -275,7 +292,10 @@ export class TypeGenerator {
275292
}
276293
}
277294

278-
private getInterfaceProperties(def: SwaggerDefinition, options: { excludeReadOnly?: boolean, excludeWriteOnly?: boolean }): OptionalKind<PropertySignatureStructure>[] {
295+
private getInterfaceProperties(def: SwaggerDefinition, options: {
296+
excludeReadOnly?: boolean,
297+
excludeWriteOnly?: boolean
298+
}): OptionalKind<PropertySignatureStructure>[] {
279299
const props: OptionalKind<PropertySignatureStructure>[] = [];
280300
if (def.properties) {
281301
Object.entries(def.properties).forEach(([propName, propDef]) => {
@@ -291,7 +311,7 @@ export class TypeGenerator {
291311
type: type,
292312
hasQuestionToken: !isRequired,
293313
docs: this.buildJSDoc(propDef),
294-
isReadonly: options.excludeWriteOnly && !!propDef.readOnly
314+
...(options.excludeWriteOnly && !!propDef.readOnly && { isReadonly: true })
295315
});
296316
});
297317
}

tests/00-core/02-utils-coverage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

33
import * as utils from '@src/core/utils.js';
4-
import { GeneratorConfig, RequestBody, SwaggerDefinition, SwaggerResponse } from '@src/core/types.js';
4+
import { GeneratorConfig, RequestBody, SwaggerDefinition } from '@src/core/types.js';
55
import { branchCoverageSpec, typeGenSpec } from '../shared/specs.js';
66

77
/**

tests/00-core/05-runtime-expressions.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ describe('Core: Runtime Expression Evaluator', () => {
142142
});
143143

144144
it('should return undefined if response is missing', () => {
145-
const noRes = { ...mockContext, response: undefined };
145+
const noRes: RuntimeContext = {
146+
url: mockContext.url,
147+
method: mockContext.method,
148+
statusCode: mockContext.statusCode,
149+
request: mockContext.request
150+
// response is undefined
151+
};
146152
expect(evaluateRuntimeExpression('$response.body', noRes)).toBeUndefined();
147153
});
148154
});

0 commit comments

Comments
 (0)