Skip to content

Commit a49b0f0

Browse files
committed
📘 doc: update doc from swagger to OpenAPI
1 parent f410e31 commit a49b0f0

File tree

5 files changed

+100
-58
lines changed

5 files changed

+100
-58
lines changed

README.md

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# @elysiajs/swagger
2-
Plugin for [elysia](https://github.com/elysiajs/elysia) to auto-generate Swagger page.
1+
# @elysiajs/openapi
2+
Plugin for [elysia](https://github.com/elysiajs/elysia) to auto-generate API documentation page.
33

44
## Installation
55
```bash
6-
bun add @elysiajs/swagger
6+
bun add @elysiajs/openapi
77
```
88

99
## Example
1010
```typescript
1111
import { Elysia, t } from 'elysia'
12-
import { swagger } from '@elysiajs/swagger'
12+
import { openapi } from '@elysiajs/openapi'
1313

1414
const app = new Elysia()
15-
.use(swagger())
15+
.use(openapi())
1616
.get('/', () => 'hi', { response: t.String({ description: 'sample description' }) })
1717
.post(
1818
'/json/:id',
@@ -43,31 +43,59 @@ const app = new Elysia()
4343
.listen(8080);
4444
```
4545

46-
Then go to `http://localhost:8080/swagger`.
46+
Then go to `http://localhost:8080/openapi`.
4747

4848
# config
4949

50-
## provider
51-
@default 'scalar'
52-
Choose between [Scalar](https://github.com/scalar/scalar) & [SwaggerUI](https://github.com/swagger-api/swagger-ui)
50+
## enabled
51+
@default true
52+
Enable/Disable the plugin
5353

54-
## scalar
55-
Customize scalarConfig, refers to [Scalar config](https://github.com/scalar/scalar/blob/main/documentation/configuration.md)
54+
## documentation
55+
OpenAPI documentation information
5656

57-
## swagger
58-
Customize Swagger config, refers to [Swagger 3.0.3 config](https://swagger.io/specification/v3)
57+
@see https://spec.openapis.org/oas/v3.0.3.html
5958

60-
## path
61-
@default '/swagger'
59+
## exclude
60+
Configuration to exclude paths or methods from documentation
61+
62+
## exclude.methods
63+
List of methods to exclude from documentation
6264

63-
The endpoint to expose Swagger
65+
## exclude.paths
66+
List of paths to exclude from documentation
6467

65-
## excludeStaticFile
68+
## exclude.staticFile
6669
@default true
6770

68-
Determine if Swagger should exclude static files.
71+
Exclude static file routes from documentation
6972

70-
## exclude
71-
@default []
73+
## exclude.tags
74+
List of tags to exclude from documentation
75+
76+
## path
77+
@default '/openapi'
7278

73-
Paths to exclude from the Swagger endpoint
79+
The endpoint to expose OpenAPI documentation frontend
80+
81+
## provider
82+
@default 'scalar'
83+
84+
OpenAPI documentation frontend between:
85+
- [Scalar](https://github.com/scalar/scalar)
86+
- [SwaggerUI](https://github.com/openapi-api/openapi-ui)
87+
- null: disable frontend
88+
89+
## references
90+
Additional OpenAPI reference for each endpoint
91+
92+
## scalar
93+
Scalar configuration, refers to [Scalar config](https://github.com/scalar/scalar/blob/main/documentation/configuration.md)
94+
95+
## specPath
96+
@default '/${path}/json'
97+
98+
The endpoint to expose OpenAPI specification in JSON format
99+
100+
## swagger
101+
Swagger config, refers to [Swagger config](https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@elysiajs/openapi",
33
"version": "1.3.2",
4-
"description": "Plugin for Elysia to auto-generate OpenAPI documentation",
4+
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/gen/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const fromTypes =
179179

180180
if (!routes[path]) routes[path] = {}
181181
// @ts-ignore
182-
routes[path][method] = schema
182+
routes[path][method.toLowerCase()] = schema
183183
}
184184

185185
return routes

src/openapi.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ export function toOpenAPISchema(
9595

9696
const method = route.method.toLowerCase()
9797

98-
if (excludePaths.includes(route.path)) continue
99-
if (excludeMethods.includes(method)) continue
98+
if (
99+
(excludeStaticFile && route.path.includes('.')) ||
100+
excludePaths.includes(route.path) ||
101+
excludeMethods.includes(method)
102+
)
103+
continue
100104

101105
const hooks: InputSchema & {
102106
detail: Partial<OpenAPIV3.OperationObject>

src/types.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,49 @@ export interface ElysiaOpenAPIConfig<
3434
enabled?: Enabled
3535

3636
/**
37-
* Customize Swagger config, refers to Swagger 2.0 config
37+
* OpenAPI config
3838
*
39-
* @see https://swagger.io/specification/v2/
39+
* @see https://spec.openapis.org/oas/v3.0.3.html
4040
*/
4141
documentation?: Omit<
4242
Partial<OpenAPIV3.Document>,
4343
| 'x-express-openapi-additional-middleware'
4444
| 'x-express-openapi-validation-strict'
4545
>
46+
47+
exclude?: {
48+
/**
49+
* Exclude methods from OpenAPI
50+
*/
51+
methods?: string[]
52+
53+
/**
54+
* Paths to exclude from OpenAPI endpoint
55+
*
56+
* @default []
57+
*/
58+
paths?: string | RegExp | (string | RegExp)[]
59+
60+
/**
61+
* Determine if OpenAPI should exclude static files.
62+
*
63+
* @default true
64+
*/
65+
staticFile?: boolean
66+
67+
/**
68+
* Exclude tags from OpenAPI
69+
*/
70+
tags?: string[]
71+
}
72+
73+
/**
74+
* The endpoint to expose OpenAPI Documentation
75+
*
76+
* @default '/openapi'
77+
*/
78+
path?: Path
79+
4680
/**
4781
* Choose your provider, Scalar or Swagger UI
4882
*
@@ -51,6 +85,12 @@ export interface ElysiaOpenAPIConfig<
5185
* @see https://github.com/swagger-api/swagger-ui
5286
*/
5387
provider?: Provider
88+
89+
/**
90+
* Additional reference for each endpoint
91+
*/
92+
references?: AdditionalReferences
93+
5494
/**
5595
* Scalar configuration to customize scalar
5696
*'
@@ -78,18 +118,13 @@ export interface ElysiaOpenAPIConfig<
78118
*/
79119
cdn?: string
80120
}
81-
/**
82-
* The endpoint to expose OpenAPI Documentation
83-
*
84-
* @default '/openapi'
85-
*/
86-
path?: Path
87121
/**
88122
* The endpoint to expose OpenAPI JSON specification
89123
*
90124
* @default '/${path}/json'
91125
*/
92126
specPath?: string
127+
93128
/**
94129
* Options to send to SwaggerUIBundle
95130
* Currently, options that are defined as functions such as requestInterceptor
@@ -142,29 +177,4 @@ export interface ElysiaOpenAPIConfig<
142177
*/
143178
cdn?: string
144179
}
145-
146-
exclude?: {
147-
/**
148-
* Paths to exclude from OpenAPI endpoint
149-
*
150-
* @default []
151-
*/
152-
paths?: string | RegExp | (string | RegExp)[]
153-
/**
154-
* Exclude methods from OpenAPI
155-
*/
156-
methods?: string[]
157-
/**
158-
* Exclude tags from OpenAPI
159-
*/
160-
tags?: string[]
161-
/**
162-
* Determine if OpenAPI should exclude static files.
163-
*
164-
* @default true
165-
*/
166-
staticFile?: boolean
167-
}
168-
169-
references?: AdditionalReferences
170180
}

0 commit comments

Comments
 (0)