@necessarylion/adonis-autoswagger 0.0.1 → 0.0.2
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/dist/parsers.d.ts +7 -0
- package/dist/parsers.js +58 -38
- package/package.json +8 -9
package/dist/parsers.d.ts
CHANGED
|
@@ -53,6 +53,13 @@ export declare class ValidatorParser {
|
|
|
53
53
|
parsePropsAndMeta(obj: any, testObj: any, validator: VineValidator<any, any>): Promise<any>;
|
|
54
54
|
objToTest(obj: any): {};
|
|
55
55
|
parseSchema(json: any, refs: any): {};
|
|
56
|
+
getMetaFromValidations(validations: any, refs: any): {
|
|
57
|
+
minimum?: number;
|
|
58
|
+
maximum?: number;
|
|
59
|
+
choices?: any;
|
|
60
|
+
pattern?: string;
|
|
61
|
+
example?: any;
|
|
62
|
+
};
|
|
56
63
|
}
|
|
57
64
|
export declare class InterfaceParser {
|
|
58
65
|
exampleGenerator: ExampleGenerator;
|
package/dist/parsers.js
CHANGED
|
@@ -780,54 +780,74 @@ class ValidatorParser {
|
|
|
780
780
|
parseSchema(json, refs) {
|
|
781
781
|
const obj = {};
|
|
782
782
|
for (const p of json["properties"]) {
|
|
783
|
-
let meta =
|
|
784
|
-
for (const v of p["validations"]) {
|
|
785
|
-
if (refs[v["ruleFnId"]].options?.example) {
|
|
786
|
-
meta = { ...meta, example: refs[v["ruleFnId"]].options.example };
|
|
787
|
-
}
|
|
788
|
-
if (refs[v["ruleFnId"]].options?.min) {
|
|
789
|
-
meta = { ...meta, minimum: refs[v["ruleFnId"]].options.min };
|
|
790
|
-
}
|
|
791
|
-
if (refs[v["ruleFnId"]].options?.max) {
|
|
792
|
-
meta = { ...meta, maximum: refs[v["ruleFnId"]].options.max };
|
|
793
|
-
}
|
|
794
|
-
if (refs[v["ruleFnId"]].options?.choices) {
|
|
795
|
-
meta = { ...meta, choices: refs[v["ruleFnId"]].options.choices };
|
|
796
|
-
}
|
|
797
|
-
if (refs[v["ruleFnId"]].options?.toString().includes("/")) {
|
|
798
|
-
meta = { ...meta, pattern: refs[v["ruleFnId"]].options.toString() };
|
|
799
|
-
}
|
|
800
|
-
}
|
|
783
|
+
let meta = this.getMetaFromValidations(p["validations"], refs);
|
|
801
784
|
// console.dir(p, { depth: null });
|
|
802
785
|
// console.dir(validations, { depth: null });
|
|
803
786
|
// console.log(min, max, choices, regex);
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
787
|
+
const type = p["type"];
|
|
788
|
+
const field = p["fieldName"];
|
|
789
|
+
if (type === "object") {
|
|
790
|
+
console.log(field, p);
|
|
791
|
+
obj[field] = { type: "object", properties: this.parseSchema(p, refs) };
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
// if array
|
|
795
|
+
if (type === "array") {
|
|
796
|
+
if (p["each"]["type"] === "object") {
|
|
797
|
+
obj[field] = {
|
|
809
798
|
type: "array",
|
|
810
|
-
items:
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
: {
|
|
816
|
-
type: "number",
|
|
817
|
-
example: meta.example ?? meta.minimum ?? this.exampleGenerator.exampleByType("number"),
|
|
818
|
-
...meta,
|
|
819
|
-
},
|
|
820
|
-
}
|
|
821
|
-
: {
|
|
822
|
-
type: "number",
|
|
823
|
-
example: meta.example ?? meta.minimum ?? this.exampleGenerator.exampleByType("number"),
|
|
824
|
-
...meta,
|
|
799
|
+
items: {
|
|
800
|
+
type: "object",
|
|
801
|
+
properties: this.parseSchema(p["each"], refs),
|
|
802
|
+
}
|
|
825
803
|
};
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
const meta = this.getMetaFromValidations(p["each"]["validations"], refs);
|
|
807
|
+
obj[field] = {
|
|
808
|
+
type: "array",
|
|
809
|
+
items: {
|
|
810
|
+
type: "number",
|
|
811
|
+
...meta,
|
|
812
|
+
example: meta.example ?? meta.minimum ?? this.exampleGenerator.exampleByType("number"),
|
|
813
|
+
},
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
obj[field] = {
|
|
819
|
+
type: "number",
|
|
820
|
+
example: meta.example ?? meta.minimum ?? this.exampleGenerator.exampleByType("number"),
|
|
821
|
+
...meta,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
}
|
|
826
825
|
if (!p["isOptional"])
|
|
827
826
|
obj[p["fieldName"]]["required"] = true;
|
|
828
827
|
}
|
|
829
828
|
return obj;
|
|
830
829
|
}
|
|
830
|
+
getMetaFromValidations(validations, refs) {
|
|
831
|
+
let meta = {};
|
|
832
|
+
for (const v of validations) {
|
|
833
|
+
if (refs[v["ruleFnId"]].options?.example) {
|
|
834
|
+
meta = { ...meta, example: refs[v["ruleFnId"]].options.example };
|
|
835
|
+
}
|
|
836
|
+
if (refs[v["ruleFnId"]].options?.min) {
|
|
837
|
+
meta = { ...meta, minimum: refs[v["ruleFnId"]].options.min };
|
|
838
|
+
}
|
|
839
|
+
if (refs[v["ruleFnId"]].options?.max) {
|
|
840
|
+
meta = { ...meta, maximum: refs[v["ruleFnId"]].options.max };
|
|
841
|
+
}
|
|
842
|
+
if (refs[v["ruleFnId"]].options?.choices) {
|
|
843
|
+
meta = { ...meta, choices: refs[v["ruleFnId"]].options.choices };
|
|
844
|
+
}
|
|
845
|
+
if (refs[v["ruleFnId"]].options?.toString().includes("/")) {
|
|
846
|
+
meta = { ...meta, pattern: refs[v["ruleFnId"]].options.toString() };
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return meta;
|
|
850
|
+
}
|
|
831
851
|
}
|
|
832
852
|
exports.ValidatorParser = ValidatorParser;
|
|
833
853
|
class InterfaceParser {
|
package/package.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@necessarylion/adonis-autoswagger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Auto-Generate swagger docs for AdonisJS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"dev": "watchexec -e ts -- tsc",
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"prepare": "npm run build"
|
|
12
|
-
},
|
|
13
7
|
"author": "Adis Durakovic <adis.durakovic@gmail.com>",
|
|
14
8
|
"repository": {
|
|
15
9
|
"type": "git",
|
|
@@ -44,5 +38,10 @@
|
|
|
44
38
|
"bracketSpacing": true,
|
|
45
39
|
"arrowParens": "always"
|
|
46
40
|
},
|
|
47
|
-
"packageManager": "pnpm@8.11.0"
|
|
48
|
-
|
|
41
|
+
"packageManager": "pnpm@8.11.0",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
44
|
+
"dev": "watchexec -e ts -- tsc",
|
|
45
|
+
"build": "tsc"
|
|
46
|
+
}
|
|
47
|
+
}
|