Skip to content

Commit 3d211f3

Browse files
authored
Merge pull request #1465 from mrzmyr/feat/throw-when-input-not-found
feat: throw when input not found
1 parent 090edb1 commit 3d211f3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.changeset/hip-geckos-fold.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'fumadocs-openapi': minor
3+
---
4+
5+
throw error, when input file is not found

packages/openapi/src/generate-file.ts

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export async function generateFiles(options: Config): Promise<void> {
7575
...urlInputs,
7676
];
7777

78+
if (resolvedInputs.length === 0) {
79+
throw new Error(
80+
`No input files found. Tried resolving: ${
81+
typeof input === 'string' ? input : input.join(', ')
82+
}`,
83+
);
84+
}
85+
7886
function getOutputPaths(result: GeneratePageOutput): string[] {
7987
let file;
8088

packages/openapi/test/index.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,33 @@ describe('Generate documents', () => {
8484
expect(fs.mkdir).toBeCalledWith(join(cwd, './out'), expect.anything());
8585
});
8686

87+
test('Generate Files - throws error when no input files found', async () => {
88+
await expect(
89+
generateFiles({
90+
input: ['./fixtures/non-existent-*.yaml'],
91+
output: './out',
92+
per: 'file',
93+
cwd,
94+
}),
95+
).rejects.toThrow(
96+
'No input files found. Tried resolving: ./fixtures/non-existent-*.yaml',
97+
);
98+
99+
await expect(
100+
generateFiles({
101+
input: [
102+
'./fixtures/non-existent-1.yaml',
103+
'./fixtures/non-existent-2.yaml',
104+
],
105+
output: './out',
106+
per: 'file',
107+
cwd,
108+
}),
109+
).rejects.toThrow(
110+
'No input files found. Tried resolving: ./fixtures/non-existent-1.yaml, ./fixtures/non-existent-2.yaml',
111+
);
112+
});
113+
87114
test('Generate Files - groupBy tag per operation', async () => {
88115
await generateFiles({
89116
input: ['./fixtures/products.yaml'],

0 commit comments

Comments
 (0)