@necessarylion/adonis-autoswagger 0.0.8 → 0.0.10
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 +30 -24
- package/dist/auto_swagger.d.ts +1 -0
- package/dist/auto_swagger.js +29 -0
- package/dist/parsers/model_parser.js +4 -0
- package/dist/scalar_custom_css.d.ts +1 -1
- package/dist/scalar_custom_css.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ pnpm i @necessarylion/adonis-autoswagger #using pnpm
|
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
_This is a fork of [adonis-autoswagger](https://github.com/ad-on-is/adonis-autoswagger) with some additional features._
|
|
22
22
|
|
|
23
23
|
## ⭐️ Features
|
|
24
24
|
|
|
@@ -467,10 +467,10 @@ Automatically generates swagger schema-descriptions based on your validators.
|
|
|
467
467
|
```ts
|
|
468
468
|
export const adminLogin = vine.compile(
|
|
469
469
|
vine.object({
|
|
470
|
-
email: vine.string().trim().example(
|
|
471
|
-
password: vine.string().trim().example(
|
|
470
|
+
email: vine.string().trim().example("admin@laconcept.de"),
|
|
471
|
+
password: vine.string().trim().example("password"),
|
|
472
472
|
})
|
|
473
|
-
)
|
|
473
|
+
);
|
|
474
474
|
```
|
|
475
475
|
|
|
476
476
|
##### Create custom validators with vine
|
|
@@ -478,38 +478,41 @@ export const adminLogin = vine.compile(
|
|
|
478
478
|
```ts
|
|
479
479
|
// start/validators/example.ts
|
|
480
480
|
|
|
481
|
-
import vine, { VineNumber, VineString, VineNativeEnum } from
|
|
482
|
-
import { EnumLike } from
|
|
481
|
+
import vine, { VineNumber, VineString, VineNativeEnum } from "@vinejs/vine";
|
|
482
|
+
import { EnumLike } from "@vinejs/vine/types";
|
|
483
483
|
|
|
484
484
|
type Options = {
|
|
485
|
-
example: any
|
|
486
|
-
}
|
|
485
|
+
example: any;
|
|
486
|
+
};
|
|
487
487
|
|
|
488
|
-
declare module
|
|
488
|
+
declare module "@vinejs/vine" {
|
|
489
489
|
interface VineString {
|
|
490
|
-
example(example: string): this
|
|
490
|
+
example(example: string): this;
|
|
491
491
|
}
|
|
492
492
|
interface VineNumber {
|
|
493
|
-
example(example: number): this
|
|
493
|
+
example(example: number): this;
|
|
494
494
|
}
|
|
495
495
|
interface VineNativeEnum<Values extends EnumLike> {
|
|
496
|
-
example(example: string): this
|
|
496
|
+
example(example: string): this;
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
export const exampleRule = vine.createRule((_: unknown, opt: Options) => {
|
|
501
|
-
return opt.example
|
|
502
|
-
})
|
|
503
|
-
|
|
504
|
-
VineString.macro(
|
|
505
|
-
return this.use(exampleRule({ example }))
|
|
506
|
-
})
|
|
507
|
-
VineNumber.macro(
|
|
508
|
-
return this.use(exampleRule({ example }))
|
|
509
|
-
})
|
|
510
|
-
VineNativeEnum.macro(
|
|
511
|
-
|
|
512
|
-
|
|
501
|
+
return opt.example;
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
VineString.macro("example", function (this: VineString, example: string) {
|
|
505
|
+
return this.use(exampleRule({ example }));
|
|
506
|
+
});
|
|
507
|
+
VineNumber.macro("example", function (this: VineNumber, example: number) {
|
|
508
|
+
return this.use(exampleRule({ example }));
|
|
509
|
+
});
|
|
510
|
+
VineNativeEnum.macro(
|
|
511
|
+
"example",
|
|
512
|
+
function (this: VineNativeEnum<any>, example: string) {
|
|
513
|
+
return this.use(exampleRule({ example }));
|
|
514
|
+
}
|
|
515
|
+
);
|
|
513
516
|
```
|
|
514
517
|
|
|
515
518
|
##### Import in `adonisrc.ts` preloads
|
|
@@ -579,6 +582,9 @@ Specify a format for that field, i.e. uuid, email, binary, etc...
|
|
|
579
582
|
**@example(foo bar)**
|
|
580
583
|
Use this field to provide own example values for specific fields
|
|
581
584
|
|
|
585
|
+
**@serializeAs(foo)**
|
|
586
|
+
Use this field to serialize for specific fields
|
|
587
|
+
|
|
582
588
|
**@props({"minLength": 10, "foo": "bar"})**
|
|
583
589
|
Use this field to provide additional properties to a field, like minLength, maxLength, etc. Needs to bee valid JSON.
|
|
584
590
|
|
package/dist/auto_swagger.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare class AutoSwagger {
|
|
|
23
23
|
writeFile(routes: AdonisRoutes, options: options): Promise<void>;
|
|
24
24
|
docs(routes: AdonisRoutes, options: options): Promise<string>;
|
|
25
25
|
private generate;
|
|
26
|
+
private requestBodyToParameters;
|
|
26
27
|
private getDataBasedOnAdonisVersion;
|
|
27
28
|
}
|
|
28
29
|
export { AutoSwagger };
|
package/dist/auto_swagger.js
CHANGED
|
@@ -339,6 +339,12 @@ class AutoSwagger {
|
|
|
339
339
|
if (method !== "GET" && method !== "DELETE") {
|
|
340
340
|
m["requestBody"] = requestBody;
|
|
341
341
|
}
|
|
342
|
+
else {
|
|
343
|
+
m["parameters"] = [
|
|
344
|
+
...m["parameters"],
|
|
345
|
+
...this.requestBodyToParameters(requestBody),
|
|
346
|
+
];
|
|
347
|
+
}
|
|
342
348
|
pattern = pattern.slice(1);
|
|
343
349
|
if (pattern === "") {
|
|
344
350
|
pattern = "/";
|
|
@@ -357,6 +363,29 @@ class AutoSwagger {
|
|
|
357
363
|
docs.paths = paths;
|
|
358
364
|
return docs;
|
|
359
365
|
}
|
|
366
|
+
requestBodyToParameters(requestBody) {
|
|
367
|
+
const schema = requestBody?.content?.["application/json"]?.schema?.["$ref"].split('/').pop();
|
|
368
|
+
if (!schema)
|
|
369
|
+
return [];
|
|
370
|
+
const properties = this.schemas[schema].properties;
|
|
371
|
+
const required = this.schemas[schema].required;
|
|
372
|
+
const parameters = [];
|
|
373
|
+
try {
|
|
374
|
+
for (const key in properties) {
|
|
375
|
+
const data = properties[key];
|
|
376
|
+
parameters.push({
|
|
377
|
+
in: 'query',
|
|
378
|
+
name: key,
|
|
379
|
+
required: required.includes(key),
|
|
380
|
+
schema: data,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return [];
|
|
386
|
+
}
|
|
387
|
+
return parameters;
|
|
388
|
+
}
|
|
360
389
|
async getDataBasedOnAdonisVersion(route) {
|
|
361
390
|
let sourceFile = "";
|
|
362
391
|
let action = "";
|
|
@@ -65,6 +65,10 @@ class ModelParser {
|
|
|
65
65
|
}
|
|
66
66
|
let splittedLine2 = splittedLine[1].replace(/;/g, "").split(":");
|
|
67
67
|
let field = splittedLine2[0].replace('?', '');
|
|
68
|
+
if (index > 0 && lines[index - 1].includes("@serializeAs")) {
|
|
69
|
+
const line = lines[index - 1];
|
|
70
|
+
field = (0, helpers_1.getBetweenBrackets)(line, "serializeAs");
|
|
71
|
+
}
|
|
68
72
|
let type = splittedLine2[1] || "";
|
|
69
73
|
type = type.trim();
|
|
70
74
|
let enums = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const scalarCustomCss = "\n/* basic theme */\n.light-mode {\n --theme-background-1: #fff;\n --theme-background-2: #fafaf9;\n --theme-background-3: rgb(245 245 245);\n\n --theme-color-1: #21201c;\n --theme-color-2: #63635d;\n --theme-color-3: #8e8e8e;\n\n --theme-color-accent: #5a45ff;\n --theme-background-accent: #5a45ff1f;\n\n --theme-border-color: color(display-p3 0.913 0.912 0.903);\n --theme-code-language-color-supersede: var(--theme-color-1);\n --theme-code-languages-background-supersede: var(--theme-background-3);\n}\n.dark-mode {\n --theme-background-1: #0f0f0f;\n --theme-background-2: #222222;\n --theme-background-3: #272727;\n\n --theme-color-1: #e2e4e8;\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: #6a737d;\n\n --theme-color-accent: #e2ddfe;\n --theme-background-accent: #3c2d6a;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-code-language-color-supersede: var(--theme-color-1);\n --theme-code-languages-background-supersede: var(--theme-background-3);\n}\n\n/* Document Sidebar */\n.light-mode .t-doc__sidebar,\n.dark-mode .t-doc__sidebar {\n --sidebar-background-1: var(--theme-background-1);\n --sidebar-color-1: var(--theme-color-1);\n --sidebar-color-2: var(--theme-color-2);\n --sidebar-border-color: var(--theme-border-color);\n\n --sidebar-item-hover-background: var(--theme-background-2);\n --sidebar-item-hover-color: currentColor;\n\n --sidebar-item-active-background: var(--theme-background-accent);\n --sidebar-color-active: var(--theme-color-accent);\n\n --sidebar-search-background: var(--theme-background-2);\n --sidebar-search-color: var(--theme-color-3);\n --sidebar-search-border-color: var(--theme-border-color);\n}\n\n/* advanced */\n.light-mode {\n --theme-color-green: #0e766e;\n --theme-color-red: #e53935;\n --theme-color-yellow: #e2931d;\n --theme-color-blue: #0f766e;\n --theme-color-orange: #f76d47;\n --theme-color-purple: #4338ca;\n}\n.dark-mode {\n --theme-color-green: #0ad8b6;\n --theme-color-red: #e5484d;\n --theme-color-yellow: #eac063;\n --theme-color-blue: #6abaff;\n --theme-color-orange: #ff9b52;\n --theme-color-purple: #6550b9;\n}\n/* custom-theme */\n.show-api-client-button:before {\n background: white !important;\n}\n.show-api-client-button span,\n.show-api-client-button svg {\n color: var(--theme-background-1) !important;\n}\n.section:not(:last-of-type),\n.section-container {\n border-top: none !important;\n border-bottom: none !important;\n}\n.section-container:after,\n.tag-section-container section.section:after {\n content: \"\";\n width: 100%;\n height: 1px;\n position: absolute;\n top: 0;\n left: 0;\n background: repeating-linear-gradient(\n 90deg,\n var(--theme-border-color) 0 4px,\n transparent 0 8px\n );\n}\n.section-container:nth-of-type(2):after {\n display: none;\n}\n.tag-section-container .section:first-of-type:after {\n display: none;\n}\n.sidebar {\n border-right: none !important;\n}\n.t-doc__sidebar {\n position: relative;\n}\n.t-doc__sidebar:after {\n content: \"\";\n width: 1px;\n height: 100%;\n position: absolute;\n right: 0;\n top: 0;\n background: repeating-linear-gradient(\n 0deg,\n var(--theme-border-color) 0 4px,\n transparent 0 8px\n );\n display: block;\n}\n.download-cta .download-button,\n.scalar-api-reference .section .markdown a {\n --theme-color-accent: var(--theme-color-1) !important;\n text-decoration: underline !important;\n cursor: pointer;\n}\n.sidebar-heading-link[tabindex=\"-1\"] .sidebar-heading-link-title {\n font-weight: bold !important;\n font-family: monospace;\n text-transform: uppercase;\n}\n.scalar .scalar-app-layout {\n max-width: 95% !important;\n box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px !important;\n}\n.scalar-container {\n background: #434343d4 !important; \n}\n";
|
|
1
|
+
export declare const scalarCustomCss = "\n/* basic theme */\n.property-name {\n color: var(--scalar-color-orange);\n}\n\n.request-body .property-name {\n color: var(--scalar-color-blue);\n}\n\n.light-mode {\n --theme-background-1: #fff;\n --theme-background-2: #fafaf9;\n --theme-background-3: rgb(245 245 245);\n\n --theme-color-1: #21201c;\n --theme-color-2: #63635d;\n --theme-color-3: #8e8e8e;\n\n --theme-color-accent: #5a45ff;\n --theme-background-accent: #5a45ff1f;\n\n --theme-border-color: color(display-p3 0.913 0.912 0.903);\n --theme-code-language-color-supersede: var(--theme-color-1);\n --theme-code-languages-background-supersede: var(--theme-background-3);\n}\n.dark-mode {\n --theme-background-1: #0f0f0f;\n --theme-background-2: #222222;\n --theme-background-3: #272727;\n\n --theme-color-1: #e2e4e8;\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: #6a737d;\n\n --theme-color-accent: #e2ddfe;\n --theme-background-accent: #3c2d6a;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-code-language-color-supersede: var(--theme-color-1);\n --theme-code-languages-background-supersede: var(--theme-background-3);\n}\n\n/* Document Sidebar */\n.light-mode .t-doc__sidebar,\n.dark-mode .t-doc__sidebar {\n --sidebar-background-1: var(--theme-background-1);\n --sidebar-color-1: var(--theme-color-1);\n --sidebar-color-2: var(--theme-color-2);\n --sidebar-border-color: var(--theme-border-color);\n\n --sidebar-item-hover-background: var(--theme-background-2);\n --sidebar-item-hover-color: currentColor;\n\n --sidebar-item-active-background: var(--theme-background-accent);\n --sidebar-color-active: var(--theme-color-accent);\n\n --sidebar-search-background: var(--theme-background-2);\n --sidebar-search-color: var(--theme-color-3);\n --sidebar-search-border-color: var(--theme-border-color);\n}\n\n/* advanced */\n.light-mode {\n --theme-color-green: #0e766e;\n --theme-color-red: #e53935;\n --theme-color-yellow: #e2931d;\n --theme-color-blue: #0f766e;\n --theme-color-orange: #f76d47;\n --theme-color-purple: #4338ca;\n}\n.dark-mode {\n --theme-color-green: #0ad8b6;\n --theme-color-red: #e5484d;\n --theme-color-yellow: #eac063;\n --theme-color-blue: #6abaff;\n --theme-color-orange: #ff9b52;\n --theme-color-purple: #6550b9;\n}\n/* custom-theme */\n.show-api-client-button:before {\n background: white !important;\n}\n.show-api-client-button span,\n.show-api-client-button svg {\n color: var(--theme-background-1) !important;\n}\n.section:not(:last-of-type),\n.section-container {\n border-top: none !important;\n border-bottom: none !important;\n}\n.section-container:after,\n.tag-section-container section.section:after {\n content: \"\";\n width: 100%;\n height: 1px;\n position: absolute;\n top: 0;\n left: 0;\n background: repeating-linear-gradient(\n 90deg,\n var(--theme-border-color) 0 4px,\n transparent 0 8px\n );\n}\n.section-container:nth-of-type(2):after {\n display: none;\n}\n.tag-section-container .section:first-of-type:after {\n display: none;\n}\n.sidebar {\n border-right: none !important;\n}\n.t-doc__sidebar {\n position: relative;\n}\n.t-doc__sidebar:after {\n content: \"\";\n width: 1px;\n height: 100%;\n position: absolute;\n right: 0;\n top: 0;\n background: repeating-linear-gradient(\n 0deg,\n var(--theme-border-color) 0 4px,\n transparent 0 8px\n );\n display: block;\n}\n.download-cta .download-button,\n.scalar-api-reference .section .markdown a {\n --theme-color-accent: var(--theme-color-1) !important;\n text-decoration: underline !important;\n cursor: pointer;\n}\n.sidebar-heading-link[tabindex=\"-1\"] .sidebar-heading-link-title {\n font-weight: bold !important;\n font-family: monospace;\n text-transform: uppercase;\n}\n.scalar .scalar-app-layout {\n max-width: 95% !important;\n box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px !important;\n}\n.scalar-container {\n background: #434343d4 !important; \n}\n";
|
|
@@ -3,6 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scalarCustomCss = void 0;
|
|
4
4
|
exports.scalarCustomCss = `
|
|
5
5
|
/* basic theme */
|
|
6
|
+
.property-name {
|
|
7
|
+
color: var(--scalar-color-orange);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.request-body .property-name {
|
|
11
|
+
color: var(--scalar-color-blue);
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
.light-mode {
|
|
7
15
|
--theme-background-1: #fff;
|
|
8
16
|
--theme-background-2: #fafaf9;
|