@necessarylion/adonis-autoswagger 0.0.4 → 0.0.6

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.
Files changed (40) hide show
  1. package/dist/adonis_helpers.d.ts +21 -0
  2. package/dist/{adonishelpers.js → adonis_helpers.js} +17 -2
  3. package/dist/auto_swagger.d.ts +28 -0
  4. package/dist/{autoswagger.js → auto_swagger.js} +43 -394
  5. package/dist/example.d.ts +47 -0
  6. package/dist/example.js +48 -1
  7. package/dist/file.d.ts +44 -0
  8. package/dist/file.js +93 -0
  9. package/dist/helpers.d.ts +11 -2
  10. package/dist/helpers.js +11 -25
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/parsers/comment_parser.d.ts +10 -0
  14. package/dist/parsers/comment_parser.js +417 -0
  15. package/dist/parsers/enum_parser.d.ts +5 -0
  16. package/dist/parsers/enum_parser.js +51 -0
  17. package/dist/parsers/helpers.d.ts +13 -0
  18. package/dist/parsers/helpers.js +38 -0
  19. package/dist/parsers/index.d.ts +6 -0
  20. package/dist/parsers/index.js +22 -0
  21. package/dist/parsers/interface_parser.d.ts +13 -0
  22. package/dist/parsers/interface_parser.js +254 -0
  23. package/dist/parsers/model_parser.d.ts +11 -0
  24. package/dist/parsers/model_parser.js +234 -0
  25. package/dist/parsers/route_parser.d.ts +10 -0
  26. package/dist/parsers/route_parser.js +46 -0
  27. package/dist/parsers/validator_parser.d.ts +7 -0
  28. package/dist/parsers/validator_parser.js +192 -0
  29. package/dist/schema.d.ts +46 -0
  30. package/dist/schema.js +266 -0
  31. package/dist/types.d.ts +16 -17
  32. package/dist/ui.d.ts +31 -0
  33. package/dist/ui.js +157 -0
  34. package/package.json +2 -2
  35. package/dist/adonishelpers.d.ts +0 -6
  36. package/dist/autoswagger.d.ts +0 -30
  37. package/dist/parsers.d.ts +0 -83
  38. package/dist/parsers.js +0 -1142
  39. /package/dist/{scalarCustomCss.d.ts → scalar_custom_css.d.ts} +0 -0
  40. /package/dist/{scalarCustomCss.js → scalar_custom_css.js} +0 -0
package/dist/ui.js ADDED
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UIService = void 0;
4
+ const scalar_custom_css_1 = require("./scalar_custom_css");
5
+ class UIService {
6
+ /**
7
+ * Swagger UI
8
+ * @param url string
9
+ * @param options options
10
+ * @returns
11
+ */
12
+ ui(url, options) {
13
+ const persistAuthString = options?.persistAuthorization
14
+ ? "persistAuthorization: true,"
15
+ : "";
16
+ return `<!DOCTYPE html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="UTF-8">
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
21
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
22
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui-standalone-preset.js"></script>
23
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui-bundle.js"></script>
24
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.3/swagger-ui.css" />
25
+ <title>Documentation</title>
26
+ </head>
27
+ <body>
28
+ <div id="swagger-ui"></div>
29
+ <script>
30
+ window.onload = function() {
31
+ SwaggerUIBundle({
32
+ url: "${url}",
33
+ dom_id: '#swagger-ui',
34
+ presets: [
35
+ SwaggerUIBundle.presets.apis,
36
+ SwaggerUIStandalonePreset
37
+ ],
38
+ layout: "BaseLayout",
39
+ ${persistAuthString}
40
+ })
41
+ }
42
+ </script>
43
+ </body>
44
+ </html>`;
45
+ }
46
+ /**
47
+ * Rapidoc UI
48
+ * @param url string
49
+ * @param style string
50
+ * @returns
51
+ */
52
+ rapidoc(url, style = "view") {
53
+ return (`
54
+ <!doctype html> <!-- Important: must specify -->
55
+ <html>
56
+ <head>
57
+ <meta charset="utf-8"> <!-- Important: rapi-doc uses utf8 characters -->
58
+ <script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
59
+ <title>Documentation</title>
60
+ </head>
61
+ <body>
62
+ <rapi-doc
63
+ spec-url = "` +
64
+ url +
65
+ `"
66
+ theme = "dark"
67
+ bg-color = "#24283b"
68
+ schema-style="tree"
69
+ schema-expand-level = "10"
70
+ header-color = "#1a1b26"
71
+ allow-try = "true"
72
+ nav-hover-bg-color = "#1a1b26"
73
+ nav-bg-color = "#24283b"
74
+ text-color = "#c0caf5"
75
+ nav-text-color = "#c0caf5"
76
+ primary-color = "#9aa5ce"
77
+ heading-text = "Documentation"
78
+ sort-tags = "true"
79
+ render-style = "` +
80
+ style +
81
+ `"
82
+ default-schema-tab = "example"
83
+ show-components = "true"
84
+ allow-spec-url-load = "false"
85
+ allow-spec-file-load = "false"
86
+ sort-endpoints-by = "path"
87
+
88
+ > </rapi-doc>
89
+ </body>
90
+ </html>
91
+ `);
92
+ }
93
+ /**
94
+ * Scalar UI
95
+ * @param url string
96
+ * @param proxyUrl string
97
+ * @returns
98
+ */
99
+ scalar(url, proxyUrl = "https://proxy.scalar.com") {
100
+ return `
101
+ <!doctype html>
102
+ <html>
103
+ <head>
104
+ <title>API Reference</title>
105
+ <meta charset="utf-8" />
106
+ <meta
107
+ name="viewport"
108
+ content="width=device-width, initial-scale=1" />
109
+ <style>
110
+ ${scalar_custom_css_1.scalarCustomCss}
111
+ </style>
112
+ </head>
113
+ <body>
114
+ <div id="app"></div>
115
+ <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
116
+ <script>
117
+ Scalar.createApiReference('#app', {
118
+ persistAuth: true,
119
+ url: '${url}',
120
+ proxyUrl: '${proxyUrl}',
121
+ theme: 'kepler',
122
+ })
123
+ </script>
124
+ </body>
125
+ </html>
126
+ `;
127
+ }
128
+ /**
129
+ * Stoplight UI
130
+ * @param url string
131
+ * @param theme "light" | "dark"
132
+ * @returns
133
+ */
134
+ stoplight(url, theme = "dark") {
135
+ return `
136
+ <!doctype html>
137
+ <html data-theme="${theme}">
138
+ <head>
139
+ <title>API Documentation - Stoplight</title>
140
+ <meta charset="utf-8" />
141
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
142
+ <script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
143
+ <link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
144
+ </head>
145
+ <body style="min-height:100vh">
146
+ <elements-api
147
+ style="display:block;height:100vh;width:100%;"
148
+ apiDescriptionUrl=${url}
149
+ router="hash"
150
+ layout="sidebar"
151
+ />
152
+ </body>
153
+ </html>
154
+ `;
155
+ }
156
+ }
157
+ exports.UIService = UIService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@necessarylion/adonis-autoswagger",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Auto-Generate swagger docs for AdonisJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,4 +45,4 @@
45
45
  "arrowParens": "always"
46
46
  },
47
47
  "packageManager": "pnpm@8.11.0"
48
- }
48
+ }
@@ -1,6 +0,0 @@
1
- export declare function serializeV6Middleware(mw: any): string[];
2
- export declare function serializeV6Handler(handler: any): Promise<any>;
3
- export declare function parseBindingReference(binding: string | [any | any, any]): Promise<{
4
- moduleNameOrPath: string;
5
- method: string;
6
- }>;
@@ -1,30 +0,0 @@
1
- import type { options } from "./types";
2
- export declare class AutoSwagger {
3
- private options;
4
- private schemas;
5
- private commentParser;
6
- private modelParser;
7
- private interfaceParser;
8
- private enumParser;
9
- private routeParser;
10
- private validatorParser;
11
- private customPaths;
12
- ui(url: string, options?: options): string;
13
- rapidoc(url: string, style?: string): string;
14
- scalar(url: string, proxyUrl?: string): string;
15
- stoplight(url: string, theme?: "light" | "dark"): string;
16
- jsonToYaml(json: any): any;
17
- json(routes: any, options: options): Promise<any>;
18
- writeFile(routes: any, options: options): Promise<void>;
19
- private readFile;
20
- docs(routes: any, options: options): Promise<any>;
21
- private generate;
22
- private getDataBasedOnAdonisVersion;
23
- private getSchemas;
24
- private getValidators;
25
- private getSerializers;
26
- private getModels;
27
- private getInterfaces;
28
- private getFiles;
29
- private getEnums;
30
- }
package/dist/parsers.d.ts DELETED
@@ -1,83 +0,0 @@
1
- import ExampleGenerator from "./example";
2
- import type { options } from "./types";
3
- import { VineValidator } from "@vinejs/vine";
4
- export declare class CommentParser {
5
- private parsedFiles;
6
- exampleGenerator: ExampleGenerator;
7
- options: options;
8
- constructor(options: options);
9
- private parseAnnotations;
10
- private parseParam;
11
- private parseResponseHeader;
12
- private parseResponseBody;
13
- private parseRequestFormDataBody;
14
- private parseBody;
15
- arrayItems(json: any): {
16
- oneOf: any[];
17
- type?: undefined;
18
- } | {
19
- type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
20
- oneOf?: undefined;
21
- };
22
- jsonToObj(json: any): {
23
- type: string;
24
- properties: {
25
- [x: string]: any;
26
- };
27
- };
28
- getAnnotations(file: string, action: string): Promise<{}>;
29
- }
30
- export declare class RouteParser {
31
- options: options;
32
- constructor(options: options);
33
- extractInfos(p: string): {
34
- tags: any[];
35
- parameters: {};
36
- pattern: string;
37
- };
38
- }
39
- export declare class ModelParser {
40
- exampleGenerator: ExampleGenerator;
41
- snakeCase: boolean;
42
- constructor(snakeCase: boolean);
43
- parseModelProperties(data: any): {
44
- name: string;
45
- props: {};
46
- required: any[];
47
- };
48
- }
49
- export declare class ValidatorParser {
50
- exampleGenerator: ExampleGenerator;
51
- constructor();
52
- validatorToObject(validator: VineValidator<any, any>): Promise<any>;
53
- parsePropsAndMeta(obj: any, testObj: any, validator: VineValidator<any, any>): Promise<any>;
54
- objToTest(obj: any): {};
55
- parseSchema(json: any, refs: any): {
56
- properties: {};
57
- };
58
- getType(type: string): string;
59
- getMetaFromValidations(validations: any, refs: any): {
60
- minimum?: number;
61
- maximum?: number;
62
- enum?: any;
63
- pattern?: string;
64
- example?: any;
65
- };
66
- }
67
- export declare class InterfaceParser {
68
- exampleGenerator: ExampleGenerator;
69
- snakeCase: boolean;
70
- schemas: any;
71
- constructor(snakeCase: boolean, schemas?: any);
72
- objToExample(obj: any): {};
73
- parseProps(obj: any): {};
74
- getInheritedProperties(baseType: string): any;
75
- parseInterfaces(data: any): {};
76
- parseExtends(line: string): string[];
77
- parseType(type: string | any, field: string): any;
78
- }
79
- export declare class EnumParser {
80
- constructor();
81
- parseEnums(data: string): Record<string, any>;
82
- private parseEnumValue;
83
- }