@elysiajs/openapi 1.4.10 → 1.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +73 -43
- package/dist/cjs/scalar/index.js +9 -2
- package/dist/cjs/types.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +73 -43
- package/dist/scalar/index.d.ts +1 -1
- package/dist/scalar/index.mjs +9 -2
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ The endpoint to expose OpenAPI documentation frontend
|
|
|
83
83
|
|
|
84
84
|
OpenAPI documentation frontend between:
|
|
85
85
|
- [Scalar](https://github.com/scalar/scalar)
|
|
86
|
-
- [SwaggerUI](https://github.com/
|
|
86
|
+
- [SwaggerUI](https://github.com/swagger-api/swagger-ui)
|
|
87
87
|
- null: disable frontend
|
|
88
88
|
|
|
89
89
|
## references
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ElysiaOpenAPIConfig } from './types';
|
|
|
5
5
|
*
|
|
6
6
|
* @see https://github.com/elysiajs/elysia-swagger
|
|
7
7
|
*/
|
|
8
|
-
export declare const openapi: <const Enabled extends boolean = true, const Path extends string = "/openapi">({ enabled, path, provider, specPath, documentation, exclude, swagger, scalar, references, mapJsonSchema }?: ElysiaOpenAPIConfig<Enabled, Path>) => Elysia<"", {
|
|
8
|
+
export declare const openapi: <const Enabled extends boolean = true, const Path extends string = "/openapi">({ enabled, path, provider, specPath, documentation, exclude, swagger, scalar, references, mapJsonSchema, embedSpec }?: ElysiaOpenAPIConfig<Enabled, Path>) => Elysia<"", {
|
|
9
9
|
decorator: {};
|
|
10
10
|
store: {};
|
|
11
11
|
derive: {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -250,7 +250,7 @@ var elysiaCSS = `.light-mode {
|
|
|
250
250
|
background-image: var(--stripes), var(--rainbow);
|
|
251
251
|
filter: opacity(4%) saturate(200%);
|
|
252
252
|
}`;
|
|
253
|
-
var ScalarRender = (info, config2) => `<!doctype html>
|
|
253
|
+
var ScalarRender = (info, config2, embedSpec) => `<!doctype html>
|
|
254
254
|
<html>
|
|
255
255
|
<head>
|
|
256
256
|
<title>${info.title}</title>
|
|
@@ -278,7 +278,14 @@ var ScalarRender = (info, config2) => `<!doctype html>
|
|
|
278
278
|
<body>
|
|
279
279
|
<script
|
|
280
280
|
id="api-reference"
|
|
281
|
-
data-
|
|
281
|
+
data-configuration='${JSON.stringify(
|
|
282
|
+
Object.assign(
|
|
283
|
+
config2,
|
|
284
|
+
{
|
|
285
|
+
content: embedSpec
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
)}'
|
|
282
289
|
>
|
|
283
290
|
</script>
|
|
284
291
|
<script src="${config2.cdn}" crossorigin></script>
|
|
@@ -9273,7 +9280,8 @@ var openapi = ({
|
|
|
9273
9280
|
swagger,
|
|
9274
9281
|
scalar,
|
|
9275
9282
|
references,
|
|
9276
|
-
mapJsonSchema
|
|
9283
|
+
mapJsonSchema,
|
|
9284
|
+
embedSpec
|
|
9277
9285
|
} = {}) => {
|
|
9278
9286
|
if (!enabled) return new import_elysia2.Elysia({ name: "@elysiajs/openapi" });
|
|
9279
9287
|
const info = {
|
|
@@ -9285,6 +9293,35 @@ var openapi = ({
|
|
|
9285
9293
|
const relativePath = specPath.startsWith("/") ? specPath.slice(1) : specPath;
|
|
9286
9294
|
let totalRoutes = 0;
|
|
9287
9295
|
let cachedSchema;
|
|
9296
|
+
const toFullSchema = ({
|
|
9297
|
+
paths,
|
|
9298
|
+
components: { schemas }
|
|
9299
|
+
}) => {
|
|
9300
|
+
return cachedSchema = {
|
|
9301
|
+
openapi: "3.0.3",
|
|
9302
|
+
...documentation,
|
|
9303
|
+
tags: !exclude?.tags ? documentation.tags : documentation.tags?.filter(
|
|
9304
|
+
(tag) => !exclude.tags?.includes(tag.name)
|
|
9305
|
+
),
|
|
9306
|
+
info: {
|
|
9307
|
+
title: "Elysia Documentation",
|
|
9308
|
+
description: "Development documentation",
|
|
9309
|
+
version: "0.0.0",
|
|
9310
|
+
...documentation.info
|
|
9311
|
+
},
|
|
9312
|
+
paths: {
|
|
9313
|
+
...paths,
|
|
9314
|
+
...documentation.paths
|
|
9315
|
+
},
|
|
9316
|
+
components: {
|
|
9317
|
+
...documentation.components,
|
|
9318
|
+
schemas: {
|
|
9319
|
+
...schemas,
|
|
9320
|
+
...documentation.components?.schemas
|
|
9321
|
+
}
|
|
9322
|
+
}
|
|
9323
|
+
};
|
|
9324
|
+
};
|
|
9288
9325
|
const app = new import_elysia2.Elysia({ name: "@elysiajs/openapi" }).use((app2) => {
|
|
9289
9326
|
if (provider === null) return app2;
|
|
9290
9327
|
const page = () => new Response(
|
|
@@ -9294,57 +9331,50 @@ var openapi = ({
|
|
|
9294
9331
|
version: "latest",
|
|
9295
9332
|
autoDarkMode: true,
|
|
9296
9333
|
...swagger
|
|
9297
|
-
}) : ScalarRender(
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9334
|
+
}) : ScalarRender(
|
|
9335
|
+
info,
|
|
9336
|
+
{
|
|
9337
|
+
url: relativePath,
|
|
9338
|
+
version: "latest",
|
|
9339
|
+
cdn: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${scalar?.version ?? "latest"}/dist/browser/standalone.min.js`,
|
|
9340
|
+
...scalar,
|
|
9341
|
+
_integration: "elysiajs"
|
|
9342
|
+
},
|
|
9343
|
+
embedSpec ? JSON.stringify(
|
|
9344
|
+
totalRoutes === app2.routes.length ? cachedSchema : toFullSchema(
|
|
9345
|
+
toOpenAPISchema(
|
|
9346
|
+
app2,
|
|
9347
|
+
exclude,
|
|
9348
|
+
references,
|
|
9349
|
+
mapJsonSchema
|
|
9350
|
+
)
|
|
9351
|
+
)
|
|
9352
|
+
) : void 0
|
|
9353
|
+
),
|
|
9304
9354
|
{
|
|
9305
9355
|
headers: {
|
|
9306
9356
|
"content-type": "text/html; charset=utf8"
|
|
9307
9357
|
}
|
|
9308
9358
|
}
|
|
9309
9359
|
);
|
|
9310
|
-
return app2.get(
|
|
9311
|
-
|
|
9312
|
-
|
|
9360
|
+
return app2.get(
|
|
9361
|
+
path,
|
|
9362
|
+
embedSpec || isCloudflareWorker() ? page : page(),
|
|
9363
|
+
{
|
|
9364
|
+
detail: {
|
|
9365
|
+
hide: true
|
|
9366
|
+
}
|
|
9313
9367
|
}
|
|
9314
|
-
|
|
9368
|
+
);
|
|
9315
9369
|
}).get(
|
|
9316
9370
|
specPath,
|
|
9317
9371
|
function openAPISchema() {
|
|
9318
|
-
if (totalRoutes === app.routes.length
|
|
9372
|
+
if (totalRoutes === app.routes.length && cachedSchema)
|
|
9373
|
+
return cachedSchema;
|
|
9319
9374
|
totalRoutes = app.routes.length;
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
} = toOpenAPISchema(app, exclude, references, mapJsonSchema);
|
|
9324
|
-
return cachedSchema = {
|
|
9325
|
-
openapi: "3.0.3",
|
|
9326
|
-
...documentation,
|
|
9327
|
-
tags: !exclude?.tags ? documentation.tags : documentation.tags?.filter(
|
|
9328
|
-
(tag) => !exclude.tags?.includes(tag.name)
|
|
9329
|
-
),
|
|
9330
|
-
info: {
|
|
9331
|
-
title: "Elysia Documentation",
|
|
9332
|
-
description: "Development documentation",
|
|
9333
|
-
version: "0.0.0",
|
|
9334
|
-
...documentation.info
|
|
9335
|
-
},
|
|
9336
|
-
paths: {
|
|
9337
|
-
...paths,
|
|
9338
|
-
...documentation.paths
|
|
9339
|
-
},
|
|
9340
|
-
components: {
|
|
9341
|
-
...documentation.components,
|
|
9342
|
-
schemas: {
|
|
9343
|
-
...schemas,
|
|
9344
|
-
...documentation.components?.schemas
|
|
9345
|
-
}
|
|
9346
|
-
}
|
|
9347
|
-
};
|
|
9375
|
+
return toFullSchema(
|
|
9376
|
+
toOpenAPISchema(app, exclude, references, mapJsonSchema)
|
|
9377
|
+
);
|
|
9348
9378
|
},
|
|
9349
9379
|
{
|
|
9350
9380
|
error({ error }) {
|
package/dist/cjs/scalar/index.js
CHANGED
|
@@ -143,7 +143,7 @@ var elysiaCSS = `.light-mode {
|
|
|
143
143
|
background-image: var(--stripes), var(--rainbow);
|
|
144
144
|
filter: opacity(4%) saturate(200%);
|
|
145
145
|
}`;
|
|
146
|
-
var ScalarRender = (info, config) => `<!doctype html>
|
|
146
|
+
var ScalarRender = (info, config, embedSpec) => `<!doctype html>
|
|
147
147
|
<html>
|
|
148
148
|
<head>
|
|
149
149
|
<title>${info.title}</title>
|
|
@@ -171,7 +171,14 @@ var ScalarRender = (info, config) => `<!doctype html>
|
|
|
171
171
|
<body>
|
|
172
172
|
<script
|
|
173
173
|
id="api-reference"
|
|
174
|
-
data-
|
|
174
|
+
data-configuration='${JSON.stringify(
|
|
175
|
+
Object.assign(
|
|
176
|
+
config,
|
|
177
|
+
{
|
|
178
|
+
content: embedSpec
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
)}'
|
|
175
182
|
>
|
|
176
183
|
</script>
|
|
177
184
|
<script src="${config.cdn}" crossorigin></script>
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -74,6 +74,14 @@ export interface ElysiaOpenAPIConfig<Enabled extends boolean = true, Path extend
|
|
|
74
74
|
* Additional reference for each endpoint
|
|
75
75
|
*/
|
|
76
76
|
references?: AdditionalReferences;
|
|
77
|
+
/**
|
|
78
|
+
* Embed OpenAPI schema to provider body if possible
|
|
79
|
+
*
|
|
80
|
+
* This is highly discouraged, unless you really have to inline OpenAPI schema
|
|
81
|
+
*
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
embedSpec?: boolean;
|
|
77
85
|
/**
|
|
78
86
|
* Mapping function from Standard schema to OpenAPI schema
|
|
79
87
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ElysiaOpenAPIConfig } from './types';
|
|
|
5
5
|
*
|
|
6
6
|
* @see https://github.com/elysiajs/elysia-swagger
|
|
7
7
|
*/
|
|
8
|
-
export declare const openapi: <const Enabled extends boolean = true, const Path extends string = "/openapi">({ enabled, path, provider, specPath, documentation, exclude, swagger, scalar, references, mapJsonSchema }?: ElysiaOpenAPIConfig<Enabled, Path>) => Elysia<"", {
|
|
8
|
+
export declare const openapi: <const Enabled extends boolean = true, const Path extends string = "/openapi">({ enabled, path, provider, specPath, documentation, exclude, swagger, scalar, references, mapJsonSchema, embedSpec }?: ElysiaOpenAPIConfig<Enabled, Path>) => Elysia<"", {
|
|
9
9
|
decorator: {};
|
|
10
10
|
store: {};
|
|
11
11
|
derive: {};
|
package/dist/index.mjs
CHANGED
|
@@ -228,7 +228,7 @@ var elysiaCSS = `.light-mode {
|
|
|
228
228
|
background-image: var(--stripes), var(--rainbow);
|
|
229
229
|
filter: opacity(4%) saturate(200%);
|
|
230
230
|
}`;
|
|
231
|
-
var ScalarRender = (info, config2) => `<!doctype html>
|
|
231
|
+
var ScalarRender = (info, config2, embedSpec) => `<!doctype html>
|
|
232
232
|
<html>
|
|
233
233
|
<head>
|
|
234
234
|
<title>${info.title}</title>
|
|
@@ -256,7 +256,14 @@ var ScalarRender = (info, config2) => `<!doctype html>
|
|
|
256
256
|
<body>
|
|
257
257
|
<script
|
|
258
258
|
id="api-reference"
|
|
259
|
-
data-
|
|
259
|
+
data-configuration='${JSON.stringify(
|
|
260
|
+
Object.assign(
|
|
261
|
+
config2,
|
|
262
|
+
{
|
|
263
|
+
content: embedSpec
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
)}'
|
|
260
267
|
>
|
|
261
268
|
</script>
|
|
262
269
|
<script src="${config2.cdn}" crossorigin></script>
|
|
@@ -9251,7 +9258,8 @@ var openapi = ({
|
|
|
9251
9258
|
swagger,
|
|
9252
9259
|
scalar,
|
|
9253
9260
|
references,
|
|
9254
|
-
mapJsonSchema
|
|
9261
|
+
mapJsonSchema,
|
|
9262
|
+
embedSpec
|
|
9255
9263
|
} = {}) => {
|
|
9256
9264
|
if (!enabled) return new Elysia({ name: "@elysiajs/openapi" });
|
|
9257
9265
|
const info = {
|
|
@@ -9263,6 +9271,35 @@ var openapi = ({
|
|
|
9263
9271
|
const relativePath = specPath.startsWith("/") ? specPath.slice(1) : specPath;
|
|
9264
9272
|
let totalRoutes = 0;
|
|
9265
9273
|
let cachedSchema;
|
|
9274
|
+
const toFullSchema = ({
|
|
9275
|
+
paths,
|
|
9276
|
+
components: { schemas }
|
|
9277
|
+
}) => {
|
|
9278
|
+
return cachedSchema = {
|
|
9279
|
+
openapi: "3.0.3",
|
|
9280
|
+
...documentation,
|
|
9281
|
+
tags: !exclude?.tags ? documentation.tags : documentation.tags?.filter(
|
|
9282
|
+
(tag) => !exclude.tags?.includes(tag.name)
|
|
9283
|
+
),
|
|
9284
|
+
info: {
|
|
9285
|
+
title: "Elysia Documentation",
|
|
9286
|
+
description: "Development documentation",
|
|
9287
|
+
version: "0.0.0",
|
|
9288
|
+
...documentation.info
|
|
9289
|
+
},
|
|
9290
|
+
paths: {
|
|
9291
|
+
...paths,
|
|
9292
|
+
...documentation.paths
|
|
9293
|
+
},
|
|
9294
|
+
components: {
|
|
9295
|
+
...documentation.components,
|
|
9296
|
+
schemas: {
|
|
9297
|
+
...schemas,
|
|
9298
|
+
...documentation.components?.schemas
|
|
9299
|
+
}
|
|
9300
|
+
}
|
|
9301
|
+
};
|
|
9302
|
+
};
|
|
9266
9303
|
const app = new Elysia({ name: "@elysiajs/openapi" }).use((app2) => {
|
|
9267
9304
|
if (provider === null) return app2;
|
|
9268
9305
|
const page = () => new Response(
|
|
@@ -9272,57 +9309,50 @@ var openapi = ({
|
|
|
9272
9309
|
version: "latest",
|
|
9273
9310
|
autoDarkMode: true,
|
|
9274
9311
|
...swagger
|
|
9275
|
-
}) : ScalarRender(
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9312
|
+
}) : ScalarRender(
|
|
9313
|
+
info,
|
|
9314
|
+
{
|
|
9315
|
+
url: relativePath,
|
|
9316
|
+
version: "latest",
|
|
9317
|
+
cdn: `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${scalar?.version ?? "latest"}/dist/browser/standalone.min.js`,
|
|
9318
|
+
...scalar,
|
|
9319
|
+
_integration: "elysiajs"
|
|
9320
|
+
},
|
|
9321
|
+
embedSpec ? JSON.stringify(
|
|
9322
|
+
totalRoutes === app2.routes.length ? cachedSchema : toFullSchema(
|
|
9323
|
+
toOpenAPISchema(
|
|
9324
|
+
app2,
|
|
9325
|
+
exclude,
|
|
9326
|
+
references,
|
|
9327
|
+
mapJsonSchema
|
|
9328
|
+
)
|
|
9329
|
+
)
|
|
9330
|
+
) : void 0
|
|
9331
|
+
),
|
|
9282
9332
|
{
|
|
9283
9333
|
headers: {
|
|
9284
9334
|
"content-type": "text/html; charset=utf8"
|
|
9285
9335
|
}
|
|
9286
9336
|
}
|
|
9287
9337
|
);
|
|
9288
|
-
return app2.get(
|
|
9289
|
-
|
|
9290
|
-
|
|
9338
|
+
return app2.get(
|
|
9339
|
+
path,
|
|
9340
|
+
embedSpec || isCloudflareWorker() ? page : page(),
|
|
9341
|
+
{
|
|
9342
|
+
detail: {
|
|
9343
|
+
hide: true
|
|
9344
|
+
}
|
|
9291
9345
|
}
|
|
9292
|
-
|
|
9346
|
+
);
|
|
9293
9347
|
}).get(
|
|
9294
9348
|
specPath,
|
|
9295
9349
|
function openAPISchema() {
|
|
9296
|
-
if (totalRoutes === app.routes.length
|
|
9350
|
+
if (totalRoutes === app.routes.length && cachedSchema)
|
|
9351
|
+
return cachedSchema;
|
|
9297
9352
|
totalRoutes = app.routes.length;
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
} = toOpenAPISchema(app, exclude, references, mapJsonSchema);
|
|
9302
|
-
return cachedSchema = {
|
|
9303
|
-
openapi: "3.0.3",
|
|
9304
|
-
...documentation,
|
|
9305
|
-
tags: !exclude?.tags ? documentation.tags : documentation.tags?.filter(
|
|
9306
|
-
(tag) => !exclude.tags?.includes(tag.name)
|
|
9307
|
-
),
|
|
9308
|
-
info: {
|
|
9309
|
-
title: "Elysia Documentation",
|
|
9310
|
-
description: "Development documentation",
|
|
9311
|
-
version: "0.0.0",
|
|
9312
|
-
...documentation.info
|
|
9313
|
-
},
|
|
9314
|
-
paths: {
|
|
9315
|
-
...paths,
|
|
9316
|
-
...documentation.paths
|
|
9317
|
-
},
|
|
9318
|
-
components: {
|
|
9319
|
-
...documentation.components,
|
|
9320
|
-
schemas: {
|
|
9321
|
-
...schemas,
|
|
9322
|
-
...documentation.components?.schemas
|
|
9323
|
-
}
|
|
9324
|
-
}
|
|
9325
|
-
};
|
|
9353
|
+
return toFullSchema(
|
|
9354
|
+
toOpenAPISchema(app, exclude, references, mapJsonSchema)
|
|
9355
|
+
);
|
|
9326
9356
|
},
|
|
9327
9357
|
{
|
|
9328
9358
|
error({ error }) {
|
package/dist/scalar/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import { ElysiaOpenAPIConfig } from '../types';
|
|
3
|
-
export declare const ScalarRender: (info: OpenAPIV3.InfoObject, config: NonNullable<ElysiaOpenAPIConfig["scalar"]
|
|
3
|
+
export declare const ScalarRender: (info: OpenAPIV3.InfoObject, config: NonNullable<ElysiaOpenAPIConfig["scalar"]>, embedSpec?: string) => string;
|
package/dist/scalar/index.mjs
CHANGED
|
@@ -119,7 +119,7 @@ var elysiaCSS = `.light-mode {
|
|
|
119
119
|
background-image: var(--stripes), var(--rainbow);
|
|
120
120
|
filter: opacity(4%) saturate(200%);
|
|
121
121
|
}`;
|
|
122
|
-
var ScalarRender = (info, config) => `<!doctype html>
|
|
122
|
+
var ScalarRender = (info, config, embedSpec) => `<!doctype html>
|
|
123
123
|
<html>
|
|
124
124
|
<head>
|
|
125
125
|
<title>${info.title}</title>
|
|
@@ -147,7 +147,14 @@ var ScalarRender = (info, config) => `<!doctype html>
|
|
|
147
147
|
<body>
|
|
148
148
|
<script
|
|
149
149
|
id="api-reference"
|
|
150
|
-
data-
|
|
150
|
+
data-configuration='${JSON.stringify(
|
|
151
|
+
Object.assign(
|
|
152
|
+
config,
|
|
153
|
+
{
|
|
154
|
+
content: embedSpec
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
)}'
|
|
151
158
|
>
|
|
152
159
|
</script>
|
|
153
160
|
<script src="${config.cdn}" crossorigin></script>
|
package/dist/types.d.ts
CHANGED
|
@@ -74,6 +74,14 @@ export interface ElysiaOpenAPIConfig<Enabled extends boolean = true, Path extend
|
|
|
74
74
|
* Additional reference for each endpoint
|
|
75
75
|
*/
|
|
76
76
|
references?: AdditionalReferences;
|
|
77
|
+
/**
|
|
78
|
+
* Embed OpenAPI schema to provider body if possible
|
|
79
|
+
*
|
|
80
|
+
* This is highly discouraged, unless you really have to inline OpenAPI schema
|
|
81
|
+
*
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
embedSpec?: boolean;
|
|
77
85
|
/**
|
|
78
86
|
* Mapping function from Standard schema to OpenAPI schema
|
|
79
87
|
*
|