@@ -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
1835app .use (
1936 " /openapi" ,
2037 openApiUIReference ({
2138 specPath: " /openapi.json" ,
2239 }),
23- )
40+ );
2441```
2542
2643Read 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 )
0 commit comments