Skip to content

Commit

Permalink
fix: solve some fix-me and ts-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AllieJonsson committed Jan 15, 2025
1 parent 6938ec7 commit ea1d8f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export const Verbs = {

export type ImportOpenApi = {
data: Record<string, unknown | OpenAPIObject>;
input: InputOptions;
input: NormalizedInputOptions;
output: NormalizedOutputOptions;
target: string;
workspace: string;
Expand Down
6 changes: 5 additions & 1 deletion packages/orval/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getRoute,
GetterPropType,
isReference,
logError,
NormalizedInputOptions,
NormalizedOutputOptions,
resolveRef,
Expand Down Expand Up @@ -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,
Expand All @@ -112,7 +117,6 @@ export const getApiBuilder = async ({
override: output.override,
context: resolvedContext,
mock: output.mock,
// @ts-expect-error // FIXME
output: output.target,
},
output,
Expand Down
5 changes: 3 additions & 2 deletions packages/orval/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from '@orval/axios';
import {
asyncReduce,
ClientFileBuilder,
ClientMockGeneratorBuilder,
ContextSpecs,
generateDependencyImports,
GeneratorClientFooter,
Expand Down Expand Up @@ -205,12 +206,13 @@ export const generateClientTitle: GeneratorClientTitle = ({
const generateMock = (
verbOption: GeneratorVerbOptions,
options: GeneratorOptions,
) => {
): ClientMockGeneratorBuilder => {
if (!options.mock) {
return {
implementation: {
function: '',
handler: '',
handlerName: '',
},
imports: [],
};
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/orval/src/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 2 additions & 4 deletions packages/orval/src/import-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
upath,
SwaggerParserOptions,
WriteSpecsBuilder,
isString,
} from '@orval/core';
import chalk from 'chalk';
import yaml from 'js-yaml';
Expand Down Expand Up @@ -62,7 +63,7 @@ export const importSpecs = async (
): Promise<WriteSpecsBuilder> => {
const { input, output } = options;

if (isObject(input.target)) {
if (!isString(input.target)) {
return importOpenApi({
data: { [workspace]: input.target },
input,
Expand All @@ -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,
Expand All @@ -87,7 +86,6 @@ export const importSpecs = async (
data,
input,
output,
// @ts-expect-error // FIXME
target: input.target,
workspace,
});
Expand Down
13 changes: 8 additions & 5 deletions packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
ClientMockBuilder,
ConfigExternal,
createLogger,
GlobalMockOptions,
GlobalOptions,
HonoOptions,
Hook,
Expand Down Expand Up @@ -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,
};
}

Expand Down

0 comments on commit ea1d8f6

Please sign in to comment.