Skip to content

Commit 23da45b

Browse files
docs: update docs
1 parent bcbec9c commit 23da45b

File tree

4 files changed

+111
-26
lines changed

4 files changed

+111
-26
lines changed

README.md

+72-2
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,93 @@ A middleware collection for using the [OpenAPI-UI](https://github.com/rookie-luo
77
- List of Contents
88
- [Usage](#Usage)
99
- [NestJS](#nestjs)
10+
- [Express](#express)
11+
- [Hono](#hono)
1012
- [License](#license)
1113

1214
## Usage
1315

1416
### NestJS
1517
```ts
16-
import { openApiUIReference } from "@openapi-ui/nestjs-openapi-ui"
18+
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
19+
import { openApiUIReference } from "@openapi-ui/nestjs-openapi-ui";
20+
21+
const app = await NestFactory.create(AppModule);
22+
23+
const config = new DocumentBuilder()
24+
.setTitle('Cats example')
25+
.setDescription('The cats API description')
26+
.setVersion('1.0')
27+
.addTag('cats')
28+
.build()
29+
30+
const document = SwaggerModule.createDocument(app, config);
31+
SwaggerModule.setup("swagger", app, document, {
32+
jsonDocumentUrl: "/openapi.json",
33+
});
1734

1835
app.use(
1936
"/openapi",
2037
openApiUIReference({
2138
specPath: "/openapi.json",
2239
}),
23-
)
40+
);
2441
```
2542

2643
Read more: [@openapi-ui/nestjs-openapi-ui](https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/packages/nestjs-openapi-ui)
2744

45+
### Express
46+
```ts
47+
import { openApiUIReference } from '@openapi-ui/express-openapi-ui';
48+
import swaggerJsdoc from "swagger-jsdoc";
49+
50+
const openApiSpec = swaggerJsdoc({
51+
definition: {
52+
openapi: "3.0.0",
53+
info: {
54+
title: "Hello World",
55+
version: "1.0",
56+
},
57+
},
58+
apis: ["./src/*.ts"], // files containing annotations as above
59+
});
60+
61+
app.get('/openapi.json', (req, res) => {
62+
res.json(openApiSpec);
63+
});
64+
65+
app.use(
66+
'/openapi',
67+
openApiUIReference({
68+
specPath: '/openapi.json',
69+
}),
70+
);
71+
```
72+
73+
Read more: [@openapi-ui/express-openapi-ui](https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/packages/express-openapi-ui)
74+
75+
### Hono
76+
```ts
77+
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui';
78+
79+
app.doc('/openapi.json', {
80+
info: {
81+
title: 'Example API',
82+
description: 'Example API description',
83+
version: '1.0.0',
84+
},
85+
openapi: '3.0.0',
86+
});
87+
88+
app.use(
89+
'/openapi',
90+
openApiUIReference({
91+
specPath: '/openapi.json',
92+
}),
93+
);
94+
```
95+
96+
Read more: [@openapi-ui/hono-openapi-ui](https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/packages/hono-openapi-ui)
97+
2898
## License
2999
[MIT](https://github.com/openapi-ui/nodejs-openapi-ui/blob/main/LICENSE)

packages/express-openapi-ui/README.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Express-OpenAPI-UI Middleware
22

3-
[![Version](https://img.shields.io/npm/v/%40openapi-ui/express-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/express-openapi-ui)
4-
[![Downloads](https://img.shields.io/npm/dm/%40openapi-ui/express-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/express-openapi-ui)
5-
[![License](https://img.shields.io/npm/l/%40openapi-ui/express-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/express-openapi-ui)
3+
[![Version](https://img.shields.io/npm/v/@openapi-ui/express-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/express-openapi-ui)
4+
[![Downloads](https://img.shields.io/npm/dm/@openapi-ui/express-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/express-openapi-ui)
65

76
## Install
87

98
```bash
109
npm install @openapi-ui/express-openapi-ui
10+
11+
pnpm install @openapi-ui/express-openapi-ui
1112
```
1213

1314
## Usage
@@ -18,48 +19,60 @@ npm install @openapi-ui/express-openapi-ui
1819
1920

2021
```ts
21-
import { openApiUIReference } from '@openapi-ui/express-openapi-ui'
22+
import { openApiUIReference } from '@openapi-ui/express-openapi-ui';
23+
import swaggerJsdoc from "swagger-jsdoc";
24+
25+
const openApiSpec = swaggerJsdoc({
26+
definition: {
27+
openapi: "3.0.0",
28+
info: {
29+
title: "Hello World",
30+
version: "1.0",
31+
},
32+
},
33+
apis: ["./src/*.ts"], // files containing annotations as above
34+
});
2235

2336
app.get('/openapi.json', (req, res) => {
24-
res.json(openApiSpec)
25-
})
37+
res.json(openApiSpec);
38+
});
2639

2740
app.use(
2841
'/openapi',
2942
openApiUIReference({
3043
specPath: '/openapi.json',
3144
}),
32-
)
45+
);
3346
```
3447

3548
[try example](https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/examples/express-openapi-ui)
3649

3750
### Themes
3851

3952
```ts
40-
import { openApiUIReference } from '@openapi-ui/nestjs-openapi-ui'
53+
import { openApiUIReference } from '@openapi-ui/express-openapi-ui';
4154

4255
app.use(
4356
"/openapi",
4457
openApiUIReference({
4558
specPath: "/openapi.json",
4659
theme: 'light', // light or dark
4760
}),
48-
)
61+
);
4962
```
5063

5164
### Custom CDN
5265

5366
You can use a custom CDN ,default is `https://unpkg.com/openapi-ui-dist`.
5467

5568
```ts
56-
import { openApiUIReference } from '@openapi-ui/nestjs-openapi-ui'
69+
import { openApiUIReference } from '@openapi-ui/express-openapi-ui';
5770

5871
app.use(
5972
"/openapi",
6073
openApiUIReference({
6174
specPath: "/openapi.json",
6275
cdn: 'https://registry.npmmirror.com/openapi-ui-dist/latest/files',
6376
}),
64-
)
77+
);
6578
```

packages/hono-openapi-ui/README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# Hono-OpenAPI-UI Middleware
22

3-
[![Version](https://img.shields.io/npm/v/%40openapi-ui/hono-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/hono-openapi-ui)
4-
[![Downloads](https://img.shields.io/npm/dm/%40openapi-ui/hono-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/hono-openapi-ui)
5-
[![License](https://img.shields.io/npm/l/%40scalar%2Fhono-api-reference)](https://www.npmjs.com/package/@openapi-ui/hono-openapi-ui)
3+
[![Version](https://img.shields.io/npm/v/@openapi-ui/hono-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/hono-openapi-ui)
4+
[![Downloads](https://img.shields.io/npm/dm/@openapi-ui/hono-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/hono-openapi-ui)
65

76
## Install
87

98
```bash
109
npm install @openapi-ui/hono-openapi-ui
10+
11+
pnpm install @openapi-ui/hono-openapi-ui
1112
```
1213

1314
## Usage
1415

1516
Set up [Zod OpenAPI Hono](https://github.com/honojs/middleware/tree/main/packages/zod-openapi) and pass an OpenAPI/Swagger spec to the `openApiUIReference` middleware:
1617

1718
```ts
18-
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui'
19+
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui';
1920

2021
app.doc('/openapi.json', {
2122
info: {
@@ -24,44 +25,44 @@ app.doc('/openapi.json', {
2425
version: '1.0.0',
2526
},
2627
openapi: '3.0.0',
27-
})
28+
});
2829

2930
app.use(
3031
'/openapi',
3132
openApiUIReference({
3233
specPath: '/openapi.json',
3334
}),
34-
)
35+
);
3536
```
3637

3738
[try example](https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/examples/hono-openapi-ui)
3839

3940
### Themes
4041

4142
```ts
42-
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui'
43+
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui';
4344

4445
app.use(
4546
'/openapi',
4647
openApiUIReference({
4748
specPath: '/openapi.json',
4849
theme: 'light', // light or dark
4950
}),
50-
)
51+
);
5152
```
5253

5354
### Custom CDN
5455

5556
You can use a custom CDN ,default is `https://unpkg.com/openapi-ui-dist`.
5657

5758
```ts
58-
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui'
59+
import { openApiUIReference } from '@openapi-ui/hono-openapi-ui';
5960

6061
app.use(
6162
'/openapi',
6263
openApiUIReference({
6364
specPath: "/openapi.json",
6465
cdn: 'https://registry.npmmirror.com/openapi-ui-dist/latest/files',
6566
}),
66-
)
67+
);
6768
```

packages/nestjs-openapi-ui/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# NestJS-OpenAPI-UI Middleware
22

3-
[![Version](https://img.shields.io/npm/v/%40openapi-ui/nestjs-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/nestjs-openapi-ui)
4-
[![Downloads](https://img.shields.io/npm/dm/%40openapi-ui/nestjs-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/nestjs-openapi-ui)
5-
[![License](https://img.shields.io/npm/l/%40openapi-ui/nestjs-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/nestjs-openapi-ui)
3+
[![Version](https://img.shields.io/npm/v/@openapi-ui/nestjs-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/nestjs-openapi-ui)
4+
[![Downloads](https://img.shields.io/npm/dm/@openapi-ui/nestjs-openapi-ui)](https://www.npmjs.com/package/@openapi-ui/nestjs-openapi-ui)
65

76
## Install
87

98
```bash
109
npm install @openapi-ui/nestjs-openapi-ui
10+
11+
pnpm install @openapi-ui/nestjs-openapi-ui
1112
```
1213

1314
## Usage

0 commit comments

Comments
 (0)