diff --git a/package.json b/package.json index cab7d194..c683ea95 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "description": "Swagger API client generator based on axios and TypeScript.", "devDependencies": { - "@tstv/tsconfig-common": "2.0.0", + "@tstv/tsconfig-common": "3.3.1", "@types/ci-info": "3.1.0", "@types/cli-interact": "0.1.2", "@types/fs-extra": "11.0.2", diff --git a/src/Swaxios.test.ts b/src/Swaxios.test.ts index faa9c39a..932b43d4 100644 --- a/src/Swaxios.test.ts +++ b/src/Swaxios.test.ts @@ -29,7 +29,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'rest/instance/ArchiveService.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/1-query-param-description.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); @@ -40,7 +40,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'APIClient.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/2-deep-nested-endpoints.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); @@ -51,7 +51,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'rest/api/v1/ExchangeService.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/3-delete-by-id-number.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); @@ -62,7 +62,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'rest/api/v1/ExchangeService.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/4-delete-by-id-number-with-response.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); @@ -74,7 +74,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'rest/api/UserService.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/5-query-param-required.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); @@ -107,14 +107,14 @@ describe('writeClient', () => { let actual = await fs.readFile(path.join(tempDir, 'interfaces/CreateAccountRequest.ts'), 'utf-8'); let expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/8-definitions-CreateAccountRequest.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); actual = await fs.readFile(path.join(tempDir, 'interfaces/CreateAccountResponse.ts'), 'utf-8'); expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/8-definitions-CreateAccountResponse.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); @@ -125,7 +125,7 @@ describe('writeClient', () => { const actual = await fs.readFile(path.join(tempDir, 'APIClient.ts'), 'utf-8'); const expected = await fs.readFile( path.resolve(__dirname, './test/snapshots/9-special-characters.ts.fixture'), - 'utf-8', + 'utf-8' ); expect(actual).toBe(expected); }); diff --git a/src/generators/APIClientGenerator.test.ts b/src/generators/APIClientGenerator.test.ts index bb88d69e..aee51a2b 100644 --- a/src/generators/APIClientGenerator.test.ts +++ b/src/generators/APIClientGenerator.test.ts @@ -40,7 +40,7 @@ describe('ResourceGenerator', () => { const generator = new APIClientGenerator(fileIndex, '.', WireSSO); const services = (await generator.generateAPI(fileIndex)) as Record; - expect(services.login.authService).not.toBe(services.post.authService); + expect(services.login!.authService).not.toBe(services.post!.authService); }); }); }); diff --git a/src/generators/APIClientGenerator.ts b/src/generators/APIClientGenerator.ts index e40384ca..66214f4d 100644 --- a/src/generators/APIClientGenerator.ts +++ b/src/generators/APIClientGenerator.ts @@ -67,7 +67,7 @@ export class APIClientGenerator extends TemplateGenerator { const relativePath = path.dirname(path.relative(this.outputDirectory, file.fullPath)).replace(/\\/g, '/'); bundledImports[relativePath] = bundledImports[relativePath] || []; - bundledImports[relativePath].push(file); + bundledImports[relativePath]?.push(file); } for (const directory of Object.values(fileIndex.directories)) { @@ -86,7 +86,7 @@ export class APIClientGenerator extends TemplateGenerator { } protected async getContext(): Promise { - const API = await this.generateAPI(this.fileIndex.directories.rest); + const API = await this.generateAPI(this.fileIndex.directories.rest!); const apiString = inspect(API, {breakLength: Infinity, depth: Infinity}).replace(/'/gm, ''); const imports = this.generateImports(this.fileIndex); diff --git a/src/generators/InterfaceGenerator.ts b/src/generators/InterfaceGenerator.ts index 79782c3e..82f3b63b 100644 --- a/src/generators/InterfaceGenerator.ts +++ b/src/generators/InterfaceGenerator.ts @@ -100,11 +100,12 @@ export class InterfaceGenerator extends TemplateGenerator { let schemaType = schemaObject.type || SwaggerType.OBJECT; - if (Array.isArray(schemaType)) { + if (Array.isArray(schemaType) && schemaType[0]) { schemaType = schemaType[0]; } - switch (schemaType.toLowerCase()) { + // TODO: Use proper assertion functions to identify "schemaType" + switch ((schemaType as string).toLowerCase()) { case SwaggerType.BOOLEAN: { return {basicType, type: TypeScriptType.BOOLEAN, imports}; } diff --git a/src/generators/MethodGenerator.test.ts b/src/generators/MethodGenerator.test.ts index 5ed8c99e..d4997ea6 100644 --- a/src/generators/MethodGenerator.test.ts +++ b/src/generators/MethodGenerator.test.ts @@ -65,7 +65,7 @@ describe('MethodGenerator', () => { expect(methodDefinition.parameterMethod).toBe('postAll'); expect(methodDefinition.pathParameters).toEqual([]); expect(methodDefinition.returnType).toBe( - '{ extraInfo: string; id: string, metadata: { certAuthnResponse: Array; issuer: string, requestURI: string } }', + '{ extraInfo: string; id: string, metadata: { certAuthnResponse: Array; issuer: string, requestURI: string } }' ); }); diff --git a/src/generators/MethodGenerator.ts b/src/generators/MethodGenerator.ts index 4b6b755e..aa8d0c0c 100644 --- a/src/generators/MethodGenerator.ts +++ b/src/generators/MethodGenerator.ts @@ -63,7 +63,7 @@ export class MethodGenerator { if (parameterMatch) { if (!this.pathParameters.length) { this.pathParameters.push({ - name: parameterMatch[1], + name: parameterMatch[1]!, type: TypeScriptType.ANY, }); } @@ -139,7 +139,7 @@ export class MethodGenerator { } const definitionString = ref.replace('#/definitions/', ''); const definition = this.spec.definitions[definitionString]; - return definition.$ref ? this.getSchemaFromRef(definition.$ref) : definition; + return definition?.$ref ? this.getSchemaFromRef(definition?.$ref) : definition; } private buildParameters(parameters?: (OpenAPIV2.ParameterObject | OpenAPIV2.ReferenceObject)[]): void { diff --git a/src/util/StringUtil.ts b/src/util/StringUtil.ts index 46060be0..4df519ec 100644 --- a/src/util/StringUtil.ts +++ b/src/util/StringUtil.ts @@ -1,7 +1,7 @@ export function camelCase(words: string[], isPascalCase: boolean = false): string { const casedWords = words.map(word => word.toLowerCase().charAt(0).toUpperCase() + word.slice(1)); if (!isPascalCase) { - casedWords[0] = casedWords[0].toLowerCase(); + casedWords[0] = casedWords[0]!.toLowerCase(); } return casedWords.join(''); } diff --git a/tsconfig.json b/tsconfig.json index 5ab00af4..ee6de8ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,6 @@ "outDir": "dist", "rootDir": "src" }, - "exclude": ["coverage", "dist", "src/temp", "src/**/*.test.ts"], + "exclude": ["coverage", "dist", "src/temp"], "extends": "@tstv/tsconfig-common/tsconfig.json" } diff --git a/yarn.lock b/yarn.lock index 799d2a9f..4bd54cdf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -291,10 +291,10 @@ resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== -"@tstv/tsconfig-common@2.0.0": - version "2.0.0" - resolved "https://registry.npmjs.org/@tstv/tsconfig-common/-/tsconfig-common-2.0.0.tgz#8be79ca4e2dfd8bed90790ec3a31ef9b5ad45ec4" - integrity sha512-WSCxPGHR1H5ZiOdBkA1ukQAPlnNT1wVXvhBgVxVyMfZ6lgMXhz/1OJn2xY21RkG+HLQwG1iIY7LwEFc5iz3xZQ== +"@tstv/tsconfig-common@3.3.1": + version "3.3.1" + resolved "https://registry.npmjs.org/@tstv/tsconfig-common/-/tsconfig-common-3.3.1.tgz#ab73b11a141d1ad289ff9f876969ea74ce147c09" + integrity sha512-OTf+DY0qd7AEBnm2Es1ytMxlIFzZejYJCsDk14JV1uEb2uCowaO1rZjOMaN/ak1RZY3bMz+9zmskPSDoUlL6yw== "@types/ci-info@3.1.0": version "3.1.0"