From dbd9c9b58cd3e2134fbdd379ec3a7756b2a93da7 Mon Sep 17 00:00:00 2001 From: Alice Jonsson <10475857+AllieJonsson@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:27:42 +0100 Subject: [PATCH] fix: solve some fix-me and ts-errors (#1825) --- packages/core/src/types.ts | 2 +- packages/orval/src/api.ts | 6 +++++- packages/orval/src/client.ts | 5 +++-- packages/orval/src/import-open-api.ts | 1 - packages/orval/src/import-specs.ts | 6 ++---- packages/orval/src/utils/options.ts | 13 ++++++++----- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 1320fcd63..67437a6d8 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -609,7 +609,7 @@ export const Verbs = { export type ImportOpenApi = { data: Record; - input: InputOptions; + input: NormalizedInputOptions; output: NormalizedOutputOptions; target: string; workspace: string; diff --git a/packages/orval/src/api.ts b/packages/orval/src/api.ts index 8fc8559e2..dc14c7788 100644 --- a/packages/orval/src/api.ts +++ b/packages/orval/src/api.ts @@ -9,6 +9,7 @@ import { getRoute, GetterPropType, isReference, + logError, NormalizedInputOptions, NormalizedOutputOptions, resolveRef, @@ -103,6 +104,10 @@ export const getApiBuilder = async ({ verbs.servers ?? context.specs[context.specKey].servers, output.baseUrl, ); + if (!output.target) { + logError('Output does not have a target'); + process.exit(1); + } const pathOperations = await generateOperations( output.client, verbsOptions, @@ -112,7 +117,6 @@ export const getApiBuilder = async ({ override: output.override, context: resolvedContext, mock: output.mock, - // @ts-expect-error // FIXME output: output.target, }, output, diff --git a/packages/orval/src/client.ts b/packages/orval/src/client.ts index b00133d8b..f17f92345 100644 --- a/packages/orval/src/client.ts +++ b/packages/orval/src/client.ts @@ -3,6 +3,7 @@ import axios from '@orval/axios'; import { asyncReduce, ClientFileBuilder, + ClientMockGeneratorBuilder, ContextSpecs, generateDependencyImports, GeneratorClientFooter, @@ -205,12 +206,13 @@ export const generateClientTitle: GeneratorClientTitle = ({ const generateMock = ( verbOption: GeneratorVerbOptions, options: GeneratorOptions, -) => { +): ClientMockGeneratorBuilder => { if (!options.mock) { return { implementation: { function: '', handler: '', + handlerName: '', }, imports: [], }; @@ -252,7 +254,6 @@ export const generateOperations = ( acc[verbOption.operationId] = { implementation: verbOption.doc + client.implementation, imports: client.imports, - // @ts-expect-error // FIXME implementationMock: generatedMock.implementation, importsMock: generatedMock.imports, tags: verbOption.tags, diff --git a/packages/orval/src/import-open-api.ts b/packages/orval/src/import-open-api.ts index c948a1445..33ad6f660 100644 --- a/packages/orval/src/import-open-api.ts +++ b/packages/orval/src/import-open-api.ts @@ -33,7 +33,6 @@ export const importOpenApi = async ({ const schemas = getApiSchemas({ input, output, target, workspace, specs }); const api = await getApiBuilder({ - // @ts-expect-error // FIXME input, output, context: { diff --git a/packages/orval/src/import-specs.ts b/packages/orval/src/import-specs.ts index 4152197b2..e4943e184 100644 --- a/packages/orval/src/import-specs.ts +++ b/packages/orval/src/import-specs.ts @@ -7,6 +7,7 @@ import { upath, SwaggerParserOptions, WriteSpecsBuilder, + isString, } from '@orval/core'; import chalk from 'chalk'; import yaml from 'js-yaml'; @@ -62,7 +63,7 @@ export const importSpecs = async ( ): Promise => { const { input, output } = options; - if (isObject(input.target)) { + if (!isString(input.target)) { return importOpenApi({ data: { [workspace]: input.target }, input, @@ -72,11 +73,9 @@ export const importSpecs = async ( }); } - // @ts-expect-error // FIXME const isPathUrl = isUrl(input.target); const data = await resolveSpecs( - // @ts-expect-error // FIXME input.target, input.parserOptions, isPathUrl, @@ -87,7 +86,6 @@ export const importSpecs = async ( data, input, output, - // @ts-expect-error // FIXME target: input.target, workspace, }); diff --git a/packages/orval/src/utils/options.ts b/packages/orval/src/utils/options.ts index 4a6542467..2472c0775 100644 --- a/packages/orval/src/utils/options.ts +++ b/packages/orval/src/utils/options.ts @@ -1,6 +1,8 @@ import { + ClientMockBuilder, ConfigExternal, createLogger, + GlobalMockOptions, GlobalOptions, HonoOptions, Hook, @@ -92,17 +94,18 @@ export const normalizeOptions = async ( workspace, ); - let mock = outputOptions.mock ?? globalOptions.mock; - if (typeof mock === 'boolean' && mock) { + const mockOption = outputOptions.mock ?? globalOptions.mock; + let mock: GlobalMockOptions | ClientMockBuilder | undefined; + if (typeof mockOption === 'boolean' && mockOption) { mock = DEFAULT_MOCK_OPTIONS; - } else if (isFunction(mock)) { + } else if (isFunction(mockOption)) { // do nothing - } else if (!mock) { + } else if (!mockOption) { mock = undefined; } else { mock = { ...DEFAULT_MOCK_OPTIONS, - ...mock, + ...mockOption, }; }