From 20d7497acb6c046f6a4206c2d8137414e17b2263 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 19 Dec 2024 23:44:28 +0800 Subject: [PATCH] fix: handle indexed access checks --- .changeset/brown-parents-explain.md | 7 +++++++ packages/client-axios/tsconfig.base.json | 1 + packages/client-fetch/src/utils.ts | 6 +++++- packages/client-fetch/tsconfig.base.json | 1 + packages/openapi-ts/src/compiler/transform.ts | 4 ++-- packages/openapi-ts/src/compiler/types.ts | 4 ++-- packages/openapi-ts/src/compiler/utils.ts | 2 +- .../src/generate/__tests__/index.test.ts | 2 +- packages/openapi-ts/src/generate/indexFile.ts | 4 ++-- packages/openapi-ts/src/index.ts | 2 +- packages/openapi-ts/src/ir/operation.ts | 2 +- packages/openapi-ts/src/ir/parameter.ts | 18 +++++++++--------- packages/openapi-ts/src/ir/parser.ts | 6 +++--- .../src/openApi/3.0.x/parser/index.ts | 11 ++++++----- .../src/openApi/3.0.x/parser/mediaType.ts | 2 +- .../src/openApi/3.0.x/parser/pagination.ts | 2 +- .../src/openApi/3.0.x/parser/schema.ts | 10 +++++----- .../src/openApi/3.1.x/parser/index.ts | 11 ++++++----- .../src/openApi/3.1.x/parser/mediaType.ts | 2 +- .../src/openApi/3.1.x/parser/pagination.ts | 2 +- .../src/openApi/3.1.x/parser/schema.ts | 4 ++-- .../src/openApi/common/parser/getDefault.ts | 2 +- .../src/openApi/common/parser/type.ts | 4 ++-- .../src/openApi/v2/parser/getOperations.ts | 2 +- .../v3/parser/__tests__/getModel.test.ts | 4 ++-- .../src/openApi/v3/parser/discriminator.ts | 4 ++-- .../src/openApi/v3/parser/getContent.ts | 6 +++--- .../src/openApi/v3/parser/getOperations.ts | 2 +- .../src/openApi/v3/parser/operation.ts | 2 +- .../@hey-api/schemas/__tests__/schemas.test.ts | 4 ++-- .../plugins/@hey-api/schemas/plugin-legacy.ts | 2 +- .../src/plugins/@hey-api/schemas/plugin.ts | 8 ++++---- .../@hey-api/sdk/__tests__/plugin.test.ts | 8 ++++---- .../src/plugins/@hey-api/sdk/plugin-legacy.ts | 8 ++++---- .../src/plugins/@hey-api/sdk/plugin.ts | 8 ++++++-- .../@hey-api/transformers/plugin-legacy.ts | 9 ++++++--- .../plugins/@hey-api/transformers/plugin.ts | 12 ++++++------ .../@hey-api/typescript/plugin-legacy.ts | 4 ++-- .../src/plugins/@hey-api/typescript/plugin.ts | 8 ++++---- .../@tanstack/query-core/plugin-legacy.ts | 8 ++++---- .../src/plugins/@tanstack/query-core/plugin.ts | 2 +- packages/openapi-ts/src/plugins/zod/plugin.ts | 4 ++-- .../src/utils/__tests__/postprocess.test.ts | 4 ++-- packages/openapi-ts/src/utils/ref.ts | 2 +- packages/openapi-ts/src/utils/stringCase.ts | 2 +- packages/openapi-ts/src/utils/type.ts | 2 +- .../client/utils.ts.snap | 6 +++++- .../client/utils.ts.snap | 6 +++++- packages/openapi-ts/test/performance.test.ts | 6 +++--- packages/openapi-ts/test/plugins.test.ts | 2 +- packages/openapi-ts/tsconfig.base.json | 1 + 51 files changed, 138 insertions(+), 107 deletions(-) create mode 100644 .changeset/brown-parents-explain.md diff --git a/.changeset/brown-parents-explain.md b/.changeset/brown-parents-explain.md new file mode 100644 index 000000000..02a976e12 --- /dev/null +++ b/.changeset/brown-parents-explain.md @@ -0,0 +1,7 @@ +--- +'@hey-api/client-axios': patch +'@hey-api/client-fetch': patch +'@hey-api/openapi-ts': patch +--- + +fix: handle indexed access checks diff --git a/packages/client-axios/tsconfig.base.json b/packages/client-axios/tsconfig.base.json index 64e31b3e5..4ae154dda 100644 --- a/packages/client-axios/tsconfig.base.json +++ b/packages/client-axios/tsconfig.base.json @@ -5,6 +5,7 @@ "module": "ESNext", "moduleResolution": "Bundler", "noImplicitOverride": true, + "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "strict": true, "target": "ES2022", diff --git a/packages/client-fetch/src/utils.ts b/packages/client-fetch/src/utils.ts index 8b43a99de..c334bd6d6 100644 --- a/packages/client-fetch/src/utils.ts +++ b/packages/client-fetch/src/utils.ts @@ -332,7 +332,11 @@ export const getParseAs = ( return; } - const cleanContent = contentType.split(';')[0].trim(); + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } if ( cleanContent.startsWith('application/json') || diff --git a/packages/client-fetch/tsconfig.base.json b/packages/client-fetch/tsconfig.base.json index 64e31b3e5..4ae154dda 100644 --- a/packages/client-fetch/tsconfig.base.json +++ b/packages/client-fetch/tsconfig.base.json @@ -5,6 +5,7 @@ "module": "ESNext", "moduleResolution": "Bundler", "noImplicitOverride": true, + "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "strict": true, "target": "ES2022", diff --git a/packages/openapi-ts/src/compiler/transform.ts b/packages/openapi-ts/src/compiler/transform.ts index d76b99086..95c47fe12 100644 --- a/packages/openapi-ts/src/compiler/transform.ts +++ b/packages/openapi-ts/src/compiler/transform.ts @@ -29,7 +29,7 @@ export const createSafeAccessExpression = (path: string[]) => createIdentifier({ text: element }), ); }, - createIdentifier({ text: path[0] }), + createIdentifier({ text: path[0]! }), ); export const createAccessExpression = (path: string[]) => @@ -39,7 +39,7 @@ export const createAccessExpression = (path: string[]) => expression, name: element, }), - createIdentifier({ text: path[0] }), + createIdentifier({ text: path[0]! }), ); /** diff --git a/packages/openapi-ts/src/compiler/types.ts b/packages/openapi-ts/src/compiler/types.ts index 05dff46b8..e84c6c453 100644 --- a/packages/openapi-ts/src/compiler/types.ts +++ b/packages/openapi-ts/src/compiler/types.ts @@ -160,8 +160,8 @@ export const toExpression = ({ // TODO; handle more than single nested level, i.e. foo.bar.baz const parts = value.split('.'); return createPropertyAccessExpression({ - expression: parts[0], - name: parts[1], + expression: parts[0]!, + name: parts[1]!, }); } return ots.string(value, unescape); diff --git a/packages/openapi-ts/src/compiler/utils.ts b/packages/openapi-ts/src/compiler/utils.ts index 1d3acdcf5..c01a03954 100644 --- a/packages/openapi-ts/src/compiler/utils.ts +++ b/packages/openapi-ts/src/compiler/utils.ts @@ -75,7 +75,7 @@ export function tsNodeToString({ */ export function stringToTsNodes(value: string): ts.Node { const file = createSourceFile(value); - return file.statements[0]; + return file.statements[0]!; } export const createIdentifier = ({ text }: { text: string }) => { diff --git a/packages/openapi-ts/src/generate/__tests__/index.test.ts b/packages/openapi-ts/src/generate/__tests__/index.test.ts index 8c6ae1931..df80fe856 100644 --- a/packages/openapi-ts/src/generate/__tests__/index.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/index.test.ts @@ -68,7 +68,7 @@ describe('generateIndexFile', () => { generateIndexFile({ files }); - files.index.write(); + files.index!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining(path.resolve('index.ts')), diff --git a/packages/openapi-ts/src/generate/indexFile.ts b/packages/openapi-ts/src/generate/indexFile.ts index d3c798445..b32629269 100644 --- a/packages/openapi-ts/src/generate/indexFile.ts +++ b/packages/openapi-ts/src/generate/indexFile.ts @@ -62,14 +62,14 @@ export const generateIndexFile = ({ files }: { files: Files }): void => { Object.keys(files) .sort() .forEach((name) => { - const file = files[name]; + const file = files[name]!; if (name === 'index' || file.isEmpty()) { return; } if (['sdk', 'types'].includes(name)) { - files.index.add( + files.index!.add( compiler.exportAllDeclaration({ module: `./${file.nameWithoutExtension()}`, }), diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index a1e8f831a..97748f5a0 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -495,7 +495,7 @@ export async function createClient( Performance.end('createClient'); - if (configs[0].logs.level === 'debug') { + if (configs[0]!.logs.level === 'debug') { const perfReport = new PerformanceReport({ totalMark: 'createClient', }); diff --git a/packages/openapi-ts/src/ir/operation.ts b/packages/openapi-ts/src/ir/operation.ts index 51b0c356c..17d52a769 100644 --- a/packages/openapi-ts/src/ir/operation.ts +++ b/packages/openapi-ts/src/ir/operation.ts @@ -46,7 +46,7 @@ export const operationPagination = ({ return { in: 'body', name: operation.body.pagination, - schema: finalSchema.properties![operation.body.pagination], + schema: finalSchema.properties![operation.body.pagination]!, }; } diff --git a/packages/openapi-ts/src/ir/parameter.ts b/packages/openapi-ts/src/ir/parameter.ts index be010f57a..fa9af8cf2 100644 --- a/packages/openapi-ts/src/ir/parameter.ts +++ b/packages/openapi-ts/src/ir/parameter.ts @@ -5,7 +5,7 @@ export const hasParameterGroupObjectRequired = ( parameterGroup?: Record, ): boolean => { for (const name in parameterGroup) { - if (parameterGroup[name].required) { + if (parameterGroup[name]!.required) { return true; } } @@ -47,7 +47,7 @@ export const parameterWithPagination = ( } for (const name in parameters.cookie) { - const parameter = parameters.cookie[name]; + const parameter = parameters.cookie[name]!; if (parameter.pagination) { return { in: parameter.location, @@ -58,13 +58,13 @@ export const parameterWithPagination = ( schema: parameter.pagination === true ? parameter.schema - : parameter.schema.properties![parameter.pagination], + : parameter.schema.properties![parameter.pagination]!, }; } } for (const name in parameters.header) { - const parameter = parameters.header[name]; + const parameter = parameters.header[name]!; if (parameter.pagination) { return { in: parameter.location, @@ -75,13 +75,13 @@ export const parameterWithPagination = ( schema: parameter.pagination === true ? parameter.schema - : parameter.schema.properties![parameter.pagination], + : parameter.schema.properties![parameter.pagination]!, }; } } for (const name in parameters.path) { - const parameter = parameters.path[name]; + const parameter = parameters.path[name]!; if (parameter.pagination) { return { in: parameter.location, @@ -92,13 +92,13 @@ export const parameterWithPagination = ( schema: parameter.pagination === true ? parameter.schema - : parameter.schema.properties![parameter.pagination], + : parameter.schema.properties![parameter.pagination]!, }; } } for (const name in parameters.query) { - const parameter = parameters.query[name]; + const parameter = parameters.query[name]!; if (parameter.pagination) { return { in: parameter.location, @@ -109,7 +109,7 @@ export const parameterWithPagination = ( schema: parameter.pagination === true ? parameter.schema - : parameter.schema.properties![parameter.pagination], + : parameter.schema.properties![parameter.pagination]!, }; } } diff --git a/packages/openapi-ts/src/ir/parser.ts b/packages/openapi-ts/src/ir/parser.ts index ececca866..e1a8e89a6 100644 --- a/packages/openapi-ts/src/ir/parser.ts +++ b/packages/openapi-ts/src/ir/parser.ts @@ -9,19 +9,19 @@ export const parseIR = async ({ context }: { context: IR.Context }) => { if (context.ir.components) { for (const name in context.ir.components.schemas) { - const schema = context.ir.components.schemas[name]; + const schema = context.ir.components.schemas[name]!; const $ref = `#/components/schemas/${name}`; await context.broadcast('schema', { $ref, name, schema }); } for (const name in context.ir.components.parameters) { - const parameter = context.ir.components.parameters[name]; + const parameter = context.ir.components.parameters[name]!; const $ref = `#/components/parameters/${name}`; await context.broadcast('parameter', { $ref, name, parameter }); } for (const name in context.ir.components.requestBodies) { - const requestBody = context.ir.components.requestBodies[name]; + const requestBody = context.ir.components.requestBodies[name]!; const $ref = `#/components/requestBodies/${name}`; await context.broadcast('requestBody', { $ref, name, requestBody }); } diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts index d893ad335..a2a8cc3f1 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts @@ -38,7 +38,8 @@ export const parseV3_0_X = (context: IR.Context) => { // TODO: parser - handle more component types, old parser handles only parameters and schemas if (context.spec.components) { for (const name in context.spec.components.securitySchemes) { - const securityOrReference = context.spec.components.securitySchemes[name]; + const securityOrReference = + context.spec.components.securitySchemes[name]!; const securitySchemeObject = '$ref' in securityOrReference ? context.resolveRef(securityOrReference.$ref) @@ -52,7 +53,7 @@ export const parseV3_0_X = (context: IR.Context) => { continue; } - const parameterOrReference = context.spec.components.parameters[name]; + const parameterOrReference = context.spec.components.parameters[name]!; const parameter = '$ref' in parameterOrReference ? context.resolveRef(parameterOrReference.$ref) @@ -72,7 +73,7 @@ export const parseV3_0_X = (context: IR.Context) => { } const requestBodyOrReference = - context.spec.components.requestBodies[name]; + context.spec.components.requestBodies[name]!; const requestBody = '$ref' in requestBodyOrReference ? context.resolveRef(requestBodyOrReference.$ref) @@ -91,7 +92,7 @@ export const parseV3_0_X = (context: IR.Context) => { continue; } - const schema = context.spec.components.schemas[name]; + const schema = context.spec.components.schemas[name]!; parseSchema({ $ref, @@ -102,7 +103,7 @@ export const parseV3_0_X = (context: IR.Context) => { } for (const path in context.spec.paths) { - const pathItem = context.spec.paths[path as keyof PathsObject]; + const pathItem = context.spec.paths[path as keyof PathsObject]!; const finalPathItem = pathItem.$ref ? { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/mediaType.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/mediaType.ts index fb8307763..50f9a358f 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/mediaType.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/mediaType.ts @@ -61,7 +61,7 @@ export const mediaTypeObject = ({ for (const mediaType in content) { return { mediaType, - schema: content[mediaType].schema, + schema: content[mediaType]!.schema, type: mediaTypeToIrMediaType({ mediaType }), }; } diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts index d3f1db074..dfa3ae0fd 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts @@ -66,7 +66,7 @@ export const paginationField = ({ paginationKeywordsRegExp.lastIndex = 0; if (paginationKeywordsRegExp.test(name)) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property !== 'boolean' && !('$ref' in property)) { const schemaType = getSchemaType({ schema: property }); diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts index e771117be..23b8b571c 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts @@ -200,7 +200,7 @@ const parseObject = ({ const schemaProperties: Record = {}; for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property === 'boolean') { // TODO: parser - handle boolean properties } else { @@ -395,14 +395,14 @@ const parseAllOf = ({ // TODO: parser - this is a hack to bring back up meta fields // without it, some schemas were missing original deprecated - if (nestedItems[0].deprecated) { - irSchema.deprecated = nestedItems[0].deprecated; + if (nestedItems[0]!.deprecated) { + irSchema.deprecated = nestedItems[0]!.deprecated; } // TODO: parser - this is a hack to bring back up meta fields // without it, some schemas were missing original description - if (nestedItems[0].description) { - irSchema.description = nestedItems[0].description; + if (nestedItems[0]!.description) { + irSchema.description = nestedItems[0]!.description; } } diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts index 69c5693e5..c1110a554 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts @@ -38,7 +38,8 @@ export const parseV3_1_X = (context: IR.Context) => { // TODO: parser - handle more component types, old parser handles only parameters and schemas if (context.spec.components) { for (const name in context.spec.components.securitySchemes) { - const securityOrReference = context.spec.components.securitySchemes[name]; + const securityOrReference = + context.spec.components.securitySchemes[name]!; const securitySchemeObject = '$ref' in securityOrReference ? context.resolveRef(securityOrReference.$ref) @@ -52,7 +53,7 @@ export const parseV3_1_X = (context: IR.Context) => { continue; } - const parameterOrReference = context.spec.components.parameters[name]; + const parameterOrReference = context.spec.components.parameters[name]!; const parameter = '$ref' in parameterOrReference ? context.resolveRef(parameterOrReference.$ref) @@ -72,7 +73,7 @@ export const parseV3_1_X = (context: IR.Context) => { } const requestBodyOrReference = - context.spec.components.requestBodies[name]; + context.spec.components.requestBodies[name]!; const requestBody = '$ref' in requestBodyOrReference ? context.resolveRef(requestBodyOrReference.$ref) @@ -91,7 +92,7 @@ export const parseV3_1_X = (context: IR.Context) => { continue; } - const schema = context.spec.components.schemas[name]; + const schema = context.spec.components.schemas[name]!; parseSchema({ $ref, @@ -102,7 +103,7 @@ export const parseV3_1_X = (context: IR.Context) => { } for (const path in context.spec.paths) { - const pathItem = context.spec.paths[path as keyof PathsObject]; + const pathItem = context.spec.paths[path as keyof PathsObject]!; const finalPathItem = pathItem.$ref ? { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/mediaType.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/mediaType.ts index 2f0357049..1ad71cc40 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/mediaType.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/mediaType.ts @@ -51,7 +51,7 @@ export const mediaTypeObject = ({ for (const mediaType in content) { return { mediaType, - schema: content[mediaType].schema, + schema: content[mediaType]!.schema, type: mediaTypeToIrMediaType({ mediaType }), }; } diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts index 539257504..f76535b53 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts @@ -62,7 +62,7 @@ export const paginationField = ({ paginationKeywordsRegExp.lastIndex = 0; if (paginationKeywordsRegExp.test(name)) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property !== 'boolean') { const schemaTypes = getSchemaTypes({ schema: property }); diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts index 2abe5332b..6549da4b9 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts @@ -253,7 +253,7 @@ const parseObject = ({ const schemaProperties: Record = {}; for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property === 'boolean') { // TODO: parser - handle boolean properties } else { @@ -820,7 +820,7 @@ const parseType = ({ irSchema, schema: { ...schema, - type: schemaTypes[0], + type: schemaTypes[0]!, }, }); } diff --git a/packages/openapi-ts/src/openApi/common/parser/getDefault.ts b/packages/openapi-ts/src/openApi/common/parser/getDefault.ts index 3fbc88e3e..ed05c3f03 100644 --- a/packages/openapi-ts/src/openApi/common/parser/getDefault.ts +++ b/packages/openapi-ts/src/openApi/common/parser/getDefault.ts @@ -26,7 +26,7 @@ export const getDefault = ( model?.export === 'enum' && model.enum?.[definition.default as number] ) { - const { value } = model.enum[definition.default as number]; + const { value } = model.enum[definition.default as number]!; return value; } return definition.default; diff --git a/packages/openapi-ts/src/openApi/common/parser/type.ts b/packages/openapi-ts/src/openApi/common/parser/type.ts index 1165285f6..0ed62f5db 100644 --- a/packages/openapi-ts/src/openApi/common/parser/type.ts +++ b/packages/openapi-ts/src/openApi/common/parser/type.ts @@ -114,11 +114,11 @@ export const getType = ({ if (matches?.length) { const match1 = getType({ debug, - type: ensureValidTypeScriptJavaScriptIdentifier(matches[1]), + type: ensureValidTypeScriptJavaScriptIdentifier(matches[1]!), }); const match2 = getType({ debug, - type: ensureValidTypeScriptJavaScriptIdentifier(matches[2]), + type: ensureValidTypeScriptJavaScriptIdentifier(matches[2]!), }); if (match1.type === 'unknown[]') { diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts index b056c3ecb..497ed9ef1 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperations.ts @@ -20,7 +20,7 @@ export const getOperations = ({ const operations: Operation[] = []; for (const path in openApi.paths) { - const pathItem = openApi.paths[path]; + const pathItem = openApi.paths[path]!; const pathParameters = getOperationParameters({ openApi, parameters: pathItem.parameters ?? [], diff --git a/packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts b/packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts index 61a56b8fb..d5648d261 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts @@ -110,7 +110,7 @@ describe('getModel', () => { openApi, types: {}, }); - expect(model.properties[0].properties.length).toBe(2); + expect(model.properties[0]!.properties.length).toBe(2); }); it('Parses any of 2', () => { @@ -129,6 +129,6 @@ describe('getModel', () => { openApi, types: {}, }); - expect(model.properties[0].properties.length).toBe(3); + expect(model.properties[0]!.properties.length).toBe(3); }); }); diff --git a/packages/openapi-ts/src/openApi/v3/parser/discriminator.ts b/packages/openapi-ts/src/openApi/v3/parser/discriminator.ts index 7eebb899e..2ddfc1fe5 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/discriminator.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/discriminator.ts @@ -7,7 +7,7 @@ import type { OpenApiDiscriminator } from '../interfaces/OpenApiDiscriminator'; const inverseDictionary = (map: Dictionary): Dictionary => { const m2: Dictionary = {}; for (const name in map) { - m2[map[name]] = name; + m2[map[name]!] = name; } return m2; }; @@ -19,7 +19,7 @@ export const findOneOfParentDiscriminator = ( if (openApi.components && parent) { for (const definitionName in openApi.components.schemas) { if (openApi.components.schemas.hasOwnProperty(definitionName)) { - const schema = openApi.components.schemas[definitionName]; + const schema = openApi.components.schemas[definitionName]!; if ( schema.discriminator && schema.oneOf?.length && diff --git a/packages/openapi-ts/src/openApi/v3/parser/getContent.ts b/packages/openapi-ts/src/openApi/v3/parser/getContent.ts index b63c5523c..c7004abdd 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getContent.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getContent.ts @@ -27,7 +27,7 @@ export const getContent = ( ): Content | undefined => { const basicMediaTypeWithSchema = Object.keys(content) .filter((mediaType) => { - const cleanMediaType = mediaType.split(';')[0].trim(); + const cleanMediaType = mediaType.split(';')[0]!.trim(); return BASIC_MEDIA_TYPES.includes(cleanMediaType); }) .find((mediaType) => Boolean(content[mediaType]?.schema)); @@ -35,7 +35,7 @@ export const getContent = ( if (basicMediaTypeWithSchema) { return { mediaType: basicMediaTypeWithSchema, - schema: content[basicMediaTypeWithSchema].schema as OpenApiSchema, + schema: content[basicMediaTypeWithSchema]!.schema as OpenApiSchema, }; } @@ -46,7 +46,7 @@ export const getContent = ( if (firstMediaTypeWithSchema) { return { mediaType: firstMediaTypeWithSchema, - schema: content[firstMediaTypeWithSchema].schema as OpenApiSchema, + schema: content[firstMediaTypeWithSchema]!.schema as OpenApiSchema, }; } }; diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts index b056c3ecb..497ed9ef1 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperations.ts @@ -20,7 +20,7 @@ export const getOperations = ({ const operations: Operation[] = []; for (const path in openApi.paths) { - const pathItem = openApi.paths[path]; + const pathItem = openApi.paths[path]!; const pathParameters = getOperationParameters({ openApi, parameters: pathItem.parameters ?? [], diff --git a/packages/openapi-ts/src/openApi/v3/parser/operation.ts b/packages/openapi-ts/src/openApi/v3/parser/operation.ts index 5cb3ebe39..1669e2f8e 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/operation.ts @@ -26,7 +26,7 @@ const mergeParameters = ( let mergedParameters = [...opParams]; let pendingParameters = [...globalParams]; while (pendingParameters.length > 0) { - const pendingParam = pendingParameters[0]; + const pendingParam = pendingParameters[0]!; pendingParameters = pendingParameters.slice(1); const canMerge = mergedParameters.every( (param) => diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts index deb68ecd4..6a3cdf798 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts @@ -76,7 +76,7 @@ describe('generateLegacySchemas', () => { }, }); - files.schemas.write(); + files.schemas!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining('schemas.gen.ts'), @@ -154,7 +154,7 @@ describe('generateLegacySchemas', () => { }, }); - files.schemas.write(); + files.schemas!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining('schemas.gen.ts'), diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts index 96f033f9d..25bdd3046 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts @@ -92,7 +92,7 @@ export const handlerLegacy: Plugin.LegacyHandler = ({ expression, name: toSchemaName(name, schema), }); - files.schemas.add(statement); + files.schemas!.add(statement); }; // OpenAPI 2.0 diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts index 4b432033b..08ab5b759 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts @@ -123,7 +123,7 @@ const schemaToJsonSchemaDraft_05 = ({ if (schema.properties) { for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property !== 'boolean') { schema.properties[name] = schemaToJsonSchemaDraft_05({ @@ -228,7 +228,7 @@ const schemaToJsonSchema2020_12 = ({ if (schema.properties) { for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; if (typeof property !== 'boolean') { schema.properties[name] = schemaToJsonSchema2020_12({ @@ -271,7 +271,7 @@ const schemasV3_0_X = ({ } for (const name in context.spec.components.schemas) { - const schema = context.spec.components.schemas[name]; + const schema = context.spec.components.schemas[name]!; const obj = schemaToJsonSchemaDraft_05({ context, plugin, @@ -299,7 +299,7 @@ const schemasV3_1_X = ({ } for (const name in context.spec.components.schemas) { - const schema = context.spec.components.schemas[name]; + const schema = context.spec.components.schemas[name]!; const obj = schemaToJsonSchema2020_12({ context, plugin, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts index f4ea1cc1f..1935cda9a 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts @@ -108,7 +108,7 @@ describe('handlerLegacy', () => { }, }); - files.sdk.write(); + files.sdk!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining(path.resolve('sdk.gen.ts')), @@ -215,7 +215,7 @@ describe('methodNameBuilder', () => { }, }); - files.sdk.write(); + files.sdk!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining(path.resolve('sdk.gen.ts')), @@ -284,7 +284,7 @@ describe('methodNameBuilder', () => { }, }); - files.sdk.write(); + files.sdk!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining(path.resolve('sdk.gen.ts')), @@ -355,7 +355,7 @@ describe('methodNameBuilder', () => { }, }); - files.sdk.write(); + files.sdk!.write(); expect(fs.writeFileSync).toHaveBeenCalledWith( expect.stringContaining(path.resolve('sdk.gen.ts')), diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts index 9437fb6c6..726559e4e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts @@ -875,21 +875,21 @@ export const handlerLegacy: Plugin.LegacyHandler = ({ client, files }) => { processService({ client, onClientImport: (imported) => { - files.sdk.import({ + files.sdk!.import({ module: clientModulePath({ config, sourceOutput: sdkOutput }), name: imported, }); }, onImport: (imported) => { - files.sdk.import({ + files.sdk!.import({ // this detection could be done safer, but it shouldn't cause any issues asType: !imported.endsWith('Transformer'), - module: `./${files.types.nameWithoutExtension()}`, + module: `./${files.types!.nameWithoutExtension()}`, name: imported, }); }, onNode: (node) => { - files.sdk.add(node); + files.sdk!.add(node); }, service, }); diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts index 6dca134c0..b9d5cc48f 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts @@ -61,7 +61,11 @@ export const getResponseType = ( return; } - const cleanContent = contentType.split(';')[0].trim(); + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } if ( cleanContent.startsWith('application/json') || @@ -254,7 +258,7 @@ const operationStatements = ({ } for (const name in operation.parameters?.query) { - const parameter = operation.parameters.query[name]; + const parameter = operation.parameters.query[name]!; if ( (parameter.schema.type === 'array' || parameter.schema.type === 'tuple') && diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts index d7badd301..f3f2a78b6 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts @@ -86,7 +86,7 @@ const processArray = (props: ModelProps) => { if (refModels.length === 1) { const { created, name: nameModelResponseTransformer } = - ensureModelResponseTransformerExists({ ...props, model: refModels[0] }); + ensureModelResponseTransformerExists({ ...props, model: refModels[0]! }); if (!created) { return []; @@ -162,7 +162,10 @@ const processModel = (props: ModelProps): ts.Statement[] => { const refModels = getRefModels(props); const { created, name: nameModelResponseTransformer } = - ensureModelResponseTransformerExists({ ...props, model: refModels[0] }); + ensureModelResponseTransformerExists({ + ...props, + model: refModels[0]!, + }); if (!created) { return []; @@ -328,7 +331,7 @@ export const handlerLegacy: Plugin.LegacyHandler = ({ $ref: `transformers/${name}`, name, }, - model: successResponses[0], + model: successResponses[0]!, onNode, onRemoveNode, path: [dataVariableName], diff --git a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts index 376ae534f..f1598b1c0 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts @@ -57,7 +57,7 @@ const schemaIrRef = ({ const parts = $ref.split('/'); return `${parts.slice(0, parts.length - 1).join('/')}/${stringCase({ case: 'camelCase', - value: parts[parts.length - 1], + value: parts[parts.length - 1]!, })}${affix}`; }; @@ -104,7 +104,7 @@ const schemaResponseTransformerNodes = ({ // append return statement if one does not already exist if ( nodes.length && - !isNodeReturnStatement({ node: nodes[nodes.length - 1] }) + !isNodeReturnStatement({ node: nodes[nodes.length - 1]! }) ) { nodes.push(compiler.returnStatement({ expression: identifierData })); } @@ -227,7 +227,7 @@ const processSchemaType = ({ ], statements: nodes.length === 1 - ? ts.isStatement(nodes[0]) + ? ts.isStatement(nodes[0]!) ? [] : [ compiler.returnStatement({ @@ -247,7 +247,7 @@ const processSchemaType = ({ const required = schema.required ?? []; for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; const propertyAccessExpression = compiler.propertyAccessExpression({ expression: dataExpression || dataVariableName, name, @@ -325,7 +325,7 @@ const processSchemaType = ({ context, dataExpression: 'item', plugin, - schema: schema.items[0], + schema: schema.items[0]!, }); } @@ -357,7 +357,7 @@ const processSchemaType = ({ thenStatement: compiler.block({ statements: nodes.length === 1 - ? ts.isStatement(nodes[0]) + ? ts.isStatement(nodes[0]!) ? [] : [ compiler.returnStatement({ diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts index b40f6f61f..fd4b32916 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts @@ -360,9 +360,9 @@ const processServiceTypes = ({ if (bodyParameter.length === 1) { bodyParameters = { ...emptyModel, - ...bodyParameter[0], + ...bodyParameter[0]!, in: 'body', - isRequired: bodyParameter[0].isRequired, + isRequired: bodyParameter[0]!.isRequired, name: 'body', prop: 'body', }; diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts index ec11e5737..1f99a6f16 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts @@ -273,7 +273,7 @@ const arrayTypeToIdentifier = ({ ); if (itemTypes.length === 1) { - return compiler.typeArrayNode(itemTypes[0]); + return compiler.typeArrayNode(itemTypes[0]!); } if (schema.logicalOperator === 'and') { @@ -434,7 +434,7 @@ const objectTypeToIdentifier = ({ let hasOptionalProperties = false; for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; const isRequired = required.includes(name); schemaProperties.push({ comment: parseSchemaJsDoc({ schema: property }), @@ -481,7 +481,7 @@ const objectTypeToIdentifier = ({ plugin, schema: indexPropertyItems.length === 1 - ? indexPropertyItems[0] + ? indexPropertyItems[0]! : { items: indexPropertyItems, logicalOperator: 'or', @@ -665,7 +665,7 @@ const irParametersToIrSchema = ({ const required: Array = []; for (const name in parameters) { - const parameter = parameters[name]; + const parameter = parameters[name]!; properties[name] = deduplicateSchema({ schema: parameter.schema, diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts index a5b333813..7ce7eb45a 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts @@ -681,7 +681,7 @@ export const handlerLegacy: Plugin.LegacyHandler< throw new Error('🚫 TanStack Query plugin does not support legacy clients'); } - const file = files[plugin.name]; + const file = files[plugin.name]!; file.import({ ...clientApi.OptionsLegacyParser, @@ -689,7 +689,7 @@ export const handlerLegacy: Plugin.LegacyHandler< }); const typesModulePath = relativeModulePath({ - moduleOutput: files.types.nameWithoutExtension(), + moduleOutput: files.types!.nameWithoutExtension(), sourceOutput: plugin.output, }); @@ -1295,7 +1295,7 @@ export const handlerLegacy: Plugin.LegacyHandler< } const sdkModulePath = relativeModulePath({ - moduleOutput: files.sdk.nameWithoutExtension(), + moduleOutput: files.sdk!.nameWithoutExtension(), sourceOutput: plugin.output, }); @@ -1309,7 +1309,7 @@ export const handlerLegacy: Plugin.LegacyHandler< if (hasUsedQueryFn) { file.import({ module: sdkModulePath, - name: queryFn.split('.')[0], + name: queryFn.split('.')[0]!, }); } } diff --git a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts index 3e6a1c6e8..5553d72a8 100644 --- a/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts +++ b/packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts @@ -1271,7 +1271,7 @@ export const handler: Plugin.Handler< module: context .file({ id: plugin.name })! .relativePathToFile({ context, id: 'sdk' }), - name: queryFn.split('.')[0], + name: queryFn.split('.')[0]!, }); } }); diff --git a/packages/openapi-ts/src/plugins/zod/plugin.ts b/packages/openapi-ts/src/plugins/zod/plugin.ts index f186c7174..ebc9be1e7 100644 --- a/packages/openapi-ts/src/plugins/zod/plugin.ts +++ b/packages/openapi-ts/src/plugins/zod/plugin.ts @@ -314,7 +314,7 @@ const objectTypeToZodSchema = ({ // let hasOptionalProperties = false; for (const name in schema.properties) { - const property = schema.properties[name]; + const property = schema.properties[name]!; const isRequired = required.includes(name); let propertyExpression = schemaToZodSchema({ @@ -779,7 +779,7 @@ const schemaToZodSchema = ({ ); if (schema.logicalOperator === 'and') { - const firstSchema = schema.items[0]; + const firstSchema = schema.items[0]!; // we want to add an intersection, but not every schema can use the same API. // if the first item contains another array or not an object, we cannot use // `.merge()` as that does not exist on `.union()` and non-object schemas. diff --git a/packages/openapi-ts/src/utils/__tests__/postprocess.test.ts b/packages/openapi-ts/src/utils/__tests__/postprocess.test.ts index 86af33c09..d35222dea 100644 --- a/packages/openapi-ts/src/utils/__tests__/postprocess.test.ts +++ b/packages/openapi-ts/src/utils/__tests__/postprocess.test.ts @@ -61,7 +61,7 @@ describe('getServices', () => { const { services } = postProcessClient(parserClient); expect(services).toHaveLength(1); - expect(services[0].name).toEqual('Default'); + expect(services[0]!.name).toEqual('Default'); }); }); @@ -94,6 +94,6 @@ describe('getServices', () => { const { services } = postProcessClient(parserClient); expect(services).toHaveLength(1); - expect(services[0].name).toEqual('Default'); + expect(services[0]!.name).toEqual('Default'); }); }); diff --git a/packages/openapi-ts/src/utils/ref.ts b/packages/openapi-ts/src/utils/ref.ts index 0a8ed840b..40c76e064 100644 --- a/packages/openapi-ts/src/utils/ref.ts +++ b/packages/openapi-ts/src/utils/ref.ts @@ -11,7 +11,7 @@ export const isRefOpenApiComponent = ($ref: string): boolean => { */ export const refToName = ($ref: string): string => { const parts = refToParts($ref); - const name = parts[parts.length - 1]; + const name = parts[parts.length - 1]!; // refs using unicode characters become encoded, didn't investigate why // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser` return decodeURI(name); diff --git a/packages/openapi-ts/src/utils/stringCase.ts b/packages/openapi-ts/src/utils/stringCase.ts index 253d96f4d..eeff2b2b6 100644 --- a/packages/openapi-ts/src/utils/stringCase.ts +++ b/packages/openapi-ts/src/utils/stringCase.ts @@ -31,7 +31,7 @@ const preserveCase = ({ _case === 'snake_case' || _case === 'SCREAMING_SNAKE_CASE' ? '_' : '-'; for (let index = 0; index < string.length; index++) { - const character = string[index]; + const character = string[index]!; isLastLastCharPreserved = index > 2 ? string[index - 3] === separator : true; diff --git a/packages/openapi-ts/src/utils/type.ts b/packages/openapi-ts/src/utils/type.ts index 2e66f896d..296708a92 100644 --- a/packages/openapi-ts/src/utils/type.ts +++ b/packages/openapi-ts/src/utils/type.ts @@ -41,7 +41,7 @@ const typeReference = (model: Model) => { * {@link https://github.com/hey-api/openapi-ts/issues/768} */ if (model.export === 'reference' && model.$refs.length === 1) { - if (model.$refs[0].startsWith(refSchemasPartial)) { + if (model.$refs[0]!.startsWith(refSchemasPartial)) { const meta = getSchemasMeta(model.base); typeNode = compiler.typeNode(meta.name); } diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle/client/utils.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle/client/utils.ts.snap index 8b43a99de..c334bd6d6 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle/client/utils.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle/client/utils.ts.snap @@ -332,7 +332,11 @@ export const getParseAs = ( return; } - const cleanContent = contentType.split(';')[0].trim(); + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } if ( cleanContent.startsWith('application/json') || diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle_transform/client/utils.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle_transform/client/utils.ts.snap index 8b43a99de..c334bd6d6 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle_transform/client/utils.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3-hey-api-client-fetch-bundle_transform/client/utils.ts.snap @@ -332,7 +332,11 @@ export const getParseAs = ( return; } - const cleanContent = contentType.split(';')[0].trim(); + const cleanContent = contentType.split(';')[0]?.trim(); + + if (!cleanContent) { + return; + } if ( cleanContent.startsWith('application/json') || diff --git a/packages/openapi-ts/test/performance.test.ts b/packages/openapi-ts/test/performance.test.ts index ecebbe05d..c78b8ba98 100644 --- a/packages/openapi-ts/test/performance.test.ts +++ b/packages/openapi-ts/test/performance.test.ts @@ -23,7 +23,7 @@ describe('performance', () => { Performance.measure('createClient'); const measures = Performance.getEntriesByName('createClient'); - expect(measures[0].duration).toBeLessThanOrEqual(1000); + expect(measures[0]!.duration).toBeLessThanOrEqual(1000); }); it('parses spec under 500ms', async () => { @@ -38,7 +38,7 @@ describe('performance', () => { Performance.measure('parser'); const measures = Performance.getEntriesByName('parser'); - expect(measures[0].duration).toBeLessThanOrEqual(500); + expect(measures[0]!.duration).toBeLessThanOrEqual(500); }); it('parses spec under 500ms (experimental)', async () => { @@ -54,6 +54,6 @@ describe('performance', () => { Performance.measure('parser'); const measures = Performance.getEntriesByName('parser'); - expect(measures[0].duration).toBeLessThanOrEqual(500); + expect(measures[0]!.duration).toBeLessThanOrEqual(500); }); }); diff --git a/packages/openapi-ts/test/plugins.test.ts b/packages/openapi-ts/test/plugins.test.ts index 62230e31e..cb46551aa 100644 --- a/packages/openapi-ts/test/plugins.test.ts +++ b/packages/openapi-ts/test/plugins.test.ts @@ -33,7 +33,7 @@ for (const version of versions) { outputDir, typeof userConfig.plugins[0] === 'string' ? userConfig.plugins[0] - : userConfig.plugins[0].name, + : userConfig.plugins[0]!.name, typeof userConfig.output === 'string' ? userConfig.output : '', ), }); diff --git a/packages/openapi-ts/tsconfig.base.json b/packages/openapi-ts/tsconfig.base.json index 64e31b3e5..4ae154dda 100644 --- a/packages/openapi-ts/tsconfig.base.json +++ b/packages/openapi-ts/tsconfig.base.json @@ -5,6 +5,7 @@ "module": "ESNext", "moduleResolution": "Bundler", "noImplicitOverride": true, + "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "strict": true, "target": "ES2022",