OpenAPI: Remove support for bin usages

This commit is contained in:
Fuma Nama
2024-03-04 18:18:00 +08:00
parent 590ed8f611
commit eacd7b0ba3
5 changed files with 30 additions and 39 deletions
+20
View File
@@ -0,0 +1,20 @@
---
'fumadocs-openapi': major
---
**Remove support for bin usages**
why: It is more flexible and faster to write a script directly.
migrate: Create a script named `scripts/generate-docs.mjs`:
```js
import { generateFiles } from 'fumadocs-openapi';
void generateFiles({
input: ['./petstore.yaml'],
output: './content/docs',
});
```
Execute it with `node ./scripts/generate-docs.mjs`.
+9 -10
View File
@@ -11,28 +11,27 @@ Install the required packages.
fumadocs-openapi
```
Create configuration file:
Create a script:
```js title="openapi.config.js"
/**
* @type {import("fumadocs-openapi").Config}
*/
module.exports = {
```js title="scripts/generate-docs.mjs"
import { generateFiles } from 'fumadocs-openapi';
void generateFiles({
input: ['./petstore.yaml'],
output: './content/docs',
};
});
```
> Only OpenAPI 3.0 is supported.
>
> It doesn't allow JSON schema specific keywords like `const`, as [they are unsupported](https://swagger.io/docs/specification/data-models/keywords)
Generate docs with a command:
Generate docs with the script:
```bash
pnpm fumadocs-openapi
node ./scripts/generate-docs.mjs
```
### Demo
[View demo](/docs/ui/museum)
[View demo](/docs/ui/museum).
-3
View File
@@ -13,9 +13,6 @@
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"fumadocs-openapi": "./dist/bin.js"
},
"files": [
"dist"
],
-25
View File
@@ -1,25 +0,0 @@
#!/usr/bin/env node
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { generateFiles, type Config } from './generate-file';
async function main(): Promise<void> {
const configName = process.argv[2];
const config = await readConfig(configName);
await generateFiles(config);
}
async function readConfig(name = 'openapi.config.js'): Promise<Config> {
const path = resolve(process.cwd(), name);
const result = (await import(pathToFileURL(path).href)) as {
default: Config;
};
if (typeof result.default !== 'object')
throw new Error('Invalid configuration');
return result.default;
}
void main();
+1 -1
View File
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['./src/index.ts', './src/bin.ts'],
entry: ['./src/index.ts'],
format: 'esm',
dts: true,
target: 'node18',