@@ -7,23 +7,93 @@ A middleware collection for using the [OpenAPI-UI](https://github.com/rookie-luo
7
7
- List of Contents
8
8
- [ Usage] ( #Usage )
9
9
- [ NestJS] ( #nestjs )
10
+ - [ Express] ( #express )
11
+ - [ Hono] ( #hono )
10
12
- [ License] ( #license )
11
13
12
14
## Usage
13
15
14
16
### NestJS
15
17
``` 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
+ });
17
34
18
35
app .use (
19
36
" /openapi" ,
20
37
openApiUIReference ({
21
38
specPath: " /openapi.json" ,
22
39
}),
23
- )
40
+ );
24
41
```
25
42
26
43
Read more: [ @openapi-ui/nestjs-openapi-ui ] ( https://github.com/openapi-ui/nodejs-openapi-ui/tree/main/packages/nestjs-openapi-ui )
27
44
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
+
28
98
## License
29
99
[ MIT] ( https://github.com/openapi-ui/nodejs-openapi-ui/blob/main/LICENSE )
0 commit comments