Skip to content

Commit 8d2ec4e

Browse files
committed
CI fixes and improved typing
1 parent 2bab11b commit 8d2ec4e

53 files changed

Lines changed: 830 additions & 241 deletions

File tree

Some content is hidden

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

src/classes/emit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ export class TypeGenerator {
549549
/* v8 ignore next */
550550
const distinct = Array.from(new Set(returnTypes));
551551
/* v8 ignore next */
552-
const returnType = distinct.includes('string | number | boolean | object | undefined | null') ? 'string | number | boolean | object | undefined | null' : distinct.join(' | ');
552+
const returnType = distinct.includes('string | number | boolean | object | undefined | null')
553+
? 'string | number | boolean | object | undefined | null'
554+
: distinct.join(' | ');
553555

554556
/* v8 ignore next */
555557
interfaceDecl.addIndexSignature({

src/classes/parse_type_converter.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ export function getTypeScriptType(
306306
// Schema: If 'propName' key exists in the object, then the object must ALSO satisfy 'depType'.
307307
// TS Intersection: ( { prop: string | number | boolean | object | undefined | null } & DepType ) | { prop?: never }
308308
/* v8 ignore next */
309-
dependencies.push(`(({ ${safeKey}: string | number | boolean | object | undefined | null } & ${depType}) | { ${safeKey}?: never })`);
309+
dependencies.push(
310+
`(({ ${safeKey}: string | number | boolean | object | undefined | null } & ${depType}) | { ${safeKey}?: never })`,
311+
);
310312
});
311313
}
312314

@@ -330,7 +332,9 @@ export function getTypeScriptType(
330332
/* v8 ignore next */
331333
if (!requiredFields) return;
332334
/* v8 ignore next */
333-
dependencies.push(`(({ ${safeKey}: string | number | boolean | object | undefined | null } & { ${requiredFields} }) | { ${safeKey}?: never })`);
335+
dependencies.push(
336+
`(({ ${safeKey}: string | number | boolean | object | undefined | null } & { ${requiredFields} }) | { ${safeKey}?: never })`,
337+
);
334338
});
335339
}
336340

@@ -640,7 +644,9 @@ function getObjectType(schema: SwaggerDefinition, config: GeneratorConfig, known
640644
/* v8 ignore next */
641645
if (explicitlyClosed) return '{}';
642646
/* v8 ignore next */
643-
return indexSignatureType ? `{ [key: string]: ${indexSignatureType} }` : '{ [key: string]: string | number | boolean | object | undefined | null }';
647+
return indexSignatureType
648+
? `{ [key: string]: ${indexSignatureType} }`
649+
: '{ [key: string]: string | number | boolean | object | undefined | null }';
644650
}
645651

646652
/* v8 ignore next */
@@ -669,7 +675,9 @@ function getObjectType(schema: SwaggerDefinition, config: GeneratorConfig, known
669675
/* v8 ignore next */
670676
if (explicitlyClosed) return '{}';
671677
/* v8 ignore next */
672-
return indexSignatureType ? `{ [key: string]: ${indexSignatureType} }` : '{ [key: string]: string | number | boolean | object | undefined | null }';
678+
return indexSignatureType
679+
? `{ [key: string]: ${indexSignatureType} }`
680+
: '{ [key: string]: string | number | boolean | object | undefined | null }';
673681
}
674682

675683
export function getRequestBodyType(

src/cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,16 @@ program
518518
result = await runGeneration(parsed.params as OpenApiValue as CliOptions, 'to_server');
519519
break;
520520
case 'to_openapi':
521-
result = (await runToOpenApi(parsed.params as OpenApiValue as ToActionOptions, true)) as OpenApiValue;
521+
result = (await runToOpenApi(
522+
parsed.params as OpenApiValue as ToActionOptions,
523+
true,
524+
)) as OpenApiValue;
522525
break;
523526
case 'to_docs_json':
524-
result = (await runToDocsJson(parsed.params as OpenApiValue as DocsJsonOptions, true)) as OpenApiValue;
527+
result = (await runToDocsJson(
528+
parsed.params as OpenApiValue as DocsJsonOptions,
529+
true,
530+
)) as OpenApiValue;
525531
break;
526532
case 'version':
527533
result = packageJson.version;

src/functions/emit_parameter_serializer.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ export class ParameterSerializerGenerator {
151151
{ name: 'explode', type: 'boolean', initializer: 'false' },
152152
{ name: 'allowReserved', type: 'boolean', initializer: 'false' },
153153
{ name: 'serialization', type: "'json' | undefined", hasQuestionToken: true },
154-
{ name: 'contentEncoderConfig', type: 'string | number | boolean | object | undefined | null', hasQuestionToken: true },
154+
{
155+
name: 'contentEncoderConfig',
156+
type: 'string | number | boolean | object | undefined | null',
157+
hasQuestionToken: true,
158+
},
155159
],
156160
returnType: 'string',
157161
statements: `
@@ -410,8 +414,16 @@ export class ParameterSerializerGenerator {
410414
{ name: 'explode', type: 'boolean', initializer: 'false' },
411415
{ name: 'serialization', type: "'json' | undefined", hasQuestionToken: true },
412416
{ name: 'contentType', type: 'string | undefined', hasQuestionToken: true },
413-
{ name: 'encoding', type: 'Record<string, string | number | boolean | object | undefined | null> | undefined', hasQuestionToken: true },
414-
{ name: 'contentEncoderConfig', type: 'string | number | boolean | object | undefined | null', hasQuestionToken: true },
417+
{
418+
name: 'encoding',
419+
type: 'Record<string, string | number | boolean | object | undefined | null> | undefined',
420+
hasQuestionToken: true,
421+
},
422+
{
423+
name: 'contentEncoderConfig',
424+
type: 'string | number | boolean | object | undefined | null',
425+
hasQuestionToken: true,
426+
},
415427
],
416428
returnType: 'string',
417429
statements: `
@@ -465,7 +477,11 @@ export class ParameterSerializerGenerator {
465477
{ name: 'explode', type: 'boolean', initializer: 'true' },
466478
{ name: 'allowReserved', type: 'boolean', initializer: 'false' },
467479
{ name: 'serialization', type: "'json' | undefined", hasQuestionToken: true },
468-
{ name: 'contentEncoderConfig', type: 'string | number | boolean | object | undefined | null', hasQuestionToken: true },
480+
{
481+
name: 'contentEncoderConfig',
482+
type: 'string | number | boolean | object | undefined | null',
483+
hasQuestionToken: true,
484+
},
469485
],
470486
returnType: 'string',
471487
statements: `
@@ -526,8 +542,16 @@ export class ParameterSerializerGenerator {
526542
{ name: 'value', type: 'string | number | boolean | object | undefined | null' },
527543
{ name: 'serialization', type: "'json' | undefined", hasQuestionToken: true },
528544
{ name: 'contentType', type: 'string | undefined', hasQuestionToken: true },
529-
{ name: 'encodings', type: 'Record<string, string | number | boolean | object | undefined | null> | undefined', hasQuestionToken: true },
530-
{ name: 'contentEncoderConfig', type: 'string | number | boolean | object | undefined | null', hasQuestionToken: true },
545+
{
546+
name: 'encodings',
547+
type: 'Record<string, string | number | boolean | object | undefined | null> | undefined',
548+
hasQuestionToken: true,
549+
},
550+
{
551+
name: 'contentEncoderConfig',
552+
type: 'string | number | boolean | object | undefined | null',
553+
hasQuestionToken: true,
554+
},
531555
],
532556
returnType: 'string',
533557
statements: `
@@ -576,7 +600,11 @@ export class ParameterSerializerGenerator {
576600
scope: Scope.Public,
577601
parameters: [
578602
{ name: 'body', type: 'string | number | boolean | object | undefined | null' },
579-
{ name: 'encodings', type: 'Record<string, string | number | boolean | object | undefined | null>', initializer: '{}' },
603+
{
604+
name: 'encodings',
605+
type: 'Record<string, string | number | boolean | object | undefined | null>',
606+
initializer: '{}',
607+
},
580608
],
581609
returnType: 'SerializedQueryParam[]',
582610
docs: [

src/functions/parse_analyzer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,11 @@ export class ServiceMethodAnalyzer {
10061006
/* v8 ignore next */
10071007
/* v8 ignore next */
10081008
/* v8 ignore start */
1009-
parameters.push({ name: 'body', type: 'string | number | boolean | object | undefined | null', hasQuestionToken: !requestBody.required });
1009+
parameters.push({
1010+
name: 'body',
1011+
type: 'string | number | boolean | object | undefined | null',
1012+
hasQuestionToken: !requestBody.required,
1013+
});
10101014
/* v8 ignore stop */
10111015
}
10121016
}

src/openapi/emit.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,11 @@ export function parseGeneratedServiceSource(sourceText: string, filePath: string
13781378
responseMediaTypes.push('text/event-stream');
13791379

13801380
/* v8 ignore start */
1381-
if (returnTypeHint && returnTypeHint !== 'string | number | boolean | object | undefined | null' && returnTypeHint !== 'void') {
1381+
if (
1382+
returnTypeHint &&
1383+
returnTypeHint !== 'string | number | boolean | object | undefined | null' &&
1384+
returnTypeHint !== 'void'
1385+
) {
13821386
if (responseMediaTypes.length === 0) responseMediaTypes.push('application/json');
13831387
} else if (methodBody.match(/this\.http\.\w+<[^>]+>/) && responseMediaTypes.length === 0) {
13841388
responseMediaTypes.push('application/json');
@@ -1771,7 +1775,11 @@ export function buildOpenApiSpecFromServices(
17711775
let schema: Record<string, OpenApiValue> = { type: schemaType };
17721776

17731777
/* v8 ignore next */
1774-
if (bodyParam?.typeHint && bodyParam.typeHint !== 'string | number | boolean | object | undefined | null' && schemas[bodyParam.typeHint]) {
1778+
if (
1779+
bodyParam?.typeHint &&
1780+
bodyParam.typeHint !== 'string | number | boolean | object | undefined | null' &&
1781+
schemas[bodyParam.typeHint]
1782+
) {
17751783
/* v8 ignore next */
17761784
schema = { $ref: `#/components/schemas/${bodyParam.typeHint}` };
17771785
/* v8 ignore next */
@@ -1942,7 +1950,11 @@ export function buildOpenApiSpecFromServices(
19421950
let s: Record<string, OpenApiValue> = { type: t.includes('json') ? 'object' : 'string' };
19431951

19441952
/* v8 ignore next */
1945-
if (op.responseTypeHint && op.responseTypeHint !== 'string | number | boolean | object | undefined | null' && schemas[op.responseTypeHint]) {
1953+
if (
1954+
op.responseTypeHint &&
1955+
op.responseTypeHint !== 'string | number | boolean | object | undefined | null' &&
1956+
schemas[op.responseTypeHint]
1957+
) {
19461958
/* v8 ignore next */
19471959
s = { $ref: `#/components/schemas/${op.responseTypeHint}` };
19481960
}

src/openapi/emit_info.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export class InfoGenerator {
3333
{ name: 'url', type: 'string', hasQuestionToken: true },
3434
{ name: 'email', type: 'string', hasQuestionToken: true },
3535
],
36-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
36+
indexSignatures: [
37+
{
38+
keyName: 'key',
39+
keyType: 'string',
40+
returnType: 'string | number | boolean | object | undefined | null',
41+
},
42+
],
3743
docs: ['Contact information for the API (OAS Contact Object).'],
3844
});
3945

@@ -46,7 +52,13 @@ export class InfoGenerator {
4652
{ name: 'url', type: 'string', hasQuestionToken: true },
4753
{ name: 'identifier', type: 'string', hasQuestionToken: true },
4854
],
49-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
55+
indexSignatures: [
56+
{
57+
keyName: 'key',
58+
keyType: 'string',
59+
returnType: 'string | number | boolean | object | undefined | null',
60+
},
61+
],
5062
docs: ['License metadata for the API (OAS License Object).'],
5163
});
5264

@@ -58,7 +70,13 @@ export class InfoGenerator {
5870
{ name: 'description', type: 'string', hasQuestionToken: true },
5971
{ name: 'url', type: 'string' },
6072
],
61-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
73+
indexSignatures: [
74+
{
75+
keyName: 'key',
76+
keyType: 'string',
77+
returnType: 'string | number | boolean | object | undefined | null',
78+
},
79+
],
6280
docs: ['External documentation metadata (OAS External Documentation Object).'],
6381
});
6482

@@ -89,7 +107,13 @@ export class InfoGenerator {
89107
hasQuestionToken: true,
90108
},
91109
],
92-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
110+
indexSignatures: [
111+
{
112+
keyName: 'key',
113+
keyType: 'string',
114+
returnType: 'string | number | boolean | object | undefined | null',
115+
},
116+
],
93117
docs: ['Interface representing the metadata of the API.'],
94118
});
95119

@@ -120,7 +144,13 @@ export class InfoGenerator {
120144
hasQuestionToken: true,
121145
},
122146
],
123-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
147+
indexSignatures: [
148+
{
149+
keyName: 'key',
150+
keyType: 'string',
151+
returnType: 'string | number | boolean | object | undefined | null',
152+
},
153+
],
124154
docs: ['Interface representing a tag defined in the API.'],
125155
});
126156

src/openapi/parse_validator.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ function getSchemaTypeKind(schema: OpenApiValue): SchemaTypeKind {
327327
/* v8 ignore stop */
328328
/* v8 ignore next */
329329
/* v8 ignore start */
330-
if ('$ref' in (schema as object) || '$dynamicRef' in (schema as object)) return 'string | number | boolean | object | undefined | null';
330+
if ('$ref' in (schema as object) || '$dynamicRef' in (schema as object))
331+
return 'string | number | boolean | object | undefined | null';
331332
/* v8 ignore stop */
332333

333334
/* v8 ignore next */
@@ -850,7 +851,11 @@ function validateParameterStyle(param: Parameter, location: string): void {
850851
const schemaType = getSchemaTypeKind(param.schema);
851852

852853
/* v8 ignore next */
853-
if (param.style === 'deepObject' && schemaType !== 'object' && schemaType !== 'string | number | boolean | object | undefined | null') {
854+
if (
855+
param.style === 'deepObject' &&
856+
schemaType !== 'object' &&
857+
schemaType !== 'string | number | boolean | object | undefined | null'
858+
) {
854859
/* v8 ignore next */
855860
throw new SpecValidationError(
856861
`Parameter '${param.name}' in '${location}' uses 'deepObject' style but schema is not an object.`,

src/routes/emit_server_url.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export class ServerUrlGenerator {
3737
{ name: 'default', type: 'string' },
3838
{ name: 'description', type: 'string', hasQuestionToken: true },
3939
],
40-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
40+
indexSignatures: [
41+
{
42+
keyName: 'key',
43+
keyType: 'string',
44+
returnType: 'string | number | boolean | object | undefined | null',
45+
},
46+
],
4147
docs: ['Server variable definition (OAS Server Variable Object).'],
4248
});
4349

@@ -55,7 +61,13 @@ export class ServerUrlGenerator {
5561
type: 'Record<string, ServerVariable>',
5662
},
5763
],
58-
indexSignatures: [{ keyName: 'key', keyType: 'string', returnType: 'string | number | boolean | object | undefined | null' }],
64+
indexSignatures: [
65+
{
66+
keyName: 'key',
67+
keyType: 'string',
68+
returnType: 'string | number | boolean | object | undefined | null',
69+
},
70+
],
5971
docs: ['Server configuration entries declared in the OpenAPI document.'],
6072
});
6173

src/vendors/angular/admin/analysis/form-model.builder.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ export class FormModelBuilder {
305305
name: prop.name,
306306
propertyName: prop.name,
307307
/* v8 ignore next */
308-
dataType: isValidTsType(valueTsType) ? `Record<string, ${valueTsType}>` : `Record<string, string | number | boolean | object | undefined | null>`,
308+
dataType: isValidTsType(valueTsType)
309+
? `Record<string, ${valueTsType}>`
310+
: `Record<string, string | number | boolean | object | undefined | null>`,
309311
defaultValue: defaultValue || {},
310312
validationRules,
311313
controlType: 'map',
@@ -555,5 +557,9 @@ export class FormModelBuilder {
555557

556558
function isValidTsType(type: string): boolean {
557559
/* v8 ignore next */
558-
return type != null && type !== 'Record<string, string | number | boolean | object | undefined | null>' && type !== 'void';
560+
return (
561+
type != null &&
562+
type !== 'Record<string, string | number | boolean | object | undefined | null>' &&
563+
type !== 'void'
564+
);
559565
}

0 commit comments

Comments
 (0)