@automatons/validator 1.0.186 → 2.1.0
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/index.d.ts +14 -3
- package/index.js +25 -5
- package/index.js.map +1 -1
- package/package.json +41 -36
- package/index.d.ts.map +0 -1
- package/schemas/v3_0.json +0 -1621
- package/schemas/v3_1.json +0 -1350
- package/validator.d.ts +0 -13
- package/validator.d.ts.map +0 -1
- package/validator.js +0 -39
- package/validator.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type Validate = {
|
|
2
|
+
keyword: string;
|
|
3
|
+
rule: string;
|
|
4
|
+
location: string;
|
|
5
|
+
};
|
|
6
|
+
declare const validator: (openapi: {
|
|
7
|
+
openapi: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
valid: boolean;
|
|
11
|
+
errors: Validate[];
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export { type Validate, validator };
|
package/index.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/validator.ts
|
|
2
|
+
import { validate as validateOpenapi30 } from "@hyperjump/json-schema/openapi-3-0";
|
|
3
|
+
import { validate as validateOpenapi31 } from "@hyperjump/json-schema/openapi-3-1";
|
|
4
|
+
import { BASIC } from "@hyperjump/json-schema/experimental";
|
|
5
|
+
var dialects = {
|
|
6
|
+
"3_0": { uri: "https://spec.openapis.org/oas/3.0/schema", validate: validateOpenapi30 },
|
|
7
|
+
"3_1": { uri: "https://spec.openapis.org/oas/3.1/schema-base", validate: validateOpenapi31 }
|
|
8
|
+
};
|
|
9
|
+
var validator = async (openapi) => {
|
|
10
|
+
const version = openapi.openapi.split(".").slice(0, 2).join("_");
|
|
11
|
+
const dialect = dialects[version];
|
|
12
|
+
if (!dialect) {
|
|
13
|
+
throw new Error("Not supported version.\nopenapi version 3.0.0 >= version < 3.2.0");
|
|
14
|
+
}
|
|
15
|
+
const output = await dialect.validate(dialect.uri, openapi, BASIC);
|
|
16
|
+
return { valid: output.valid, errors: errorExtractor(output) };
|
|
17
|
+
};
|
|
18
|
+
var errorExtractor = (output) => (output.errors ?? []).map((error) => ({
|
|
19
|
+
keyword: error.keyword?.split("/").pop() ?? "",
|
|
20
|
+
rule: error.absoluteKeywordLocation?.split("#")[1] ?? "",
|
|
21
|
+
location: error.instanceLocation ?? ""
|
|
22
|
+
}));
|
|
23
|
+
export {
|
|
24
|
+
validator
|
|
25
|
+
};
|
|
6
26
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/validator.ts"],"sourcesContent":["import {validate as validateOpenapi30} from \"@hyperjump/json-schema/openapi-3-0\";\nimport {validate as validateOpenapi31} from \"@hyperjump/json-schema/openapi-3-1\";\nimport {BASIC} from \"@hyperjump/json-schema/experimental\";\nimport type {Json} from \"@hyperjump/json-pointer\";\n\nexport type Validate = {\n keyword: string;\n rule: string;\n location: string;\n};\n\ntype OutputUnit = {\n valid: boolean;\n keyword?: string;\n absoluteKeywordLocation?: string;\n instanceLocation?: string;\n errors?: OutputUnit[];\n};\n\nconst dialects = {\n \"3_0\": {uri: \"https://spec.openapis.org/oas/3.0/schema\", validate: validateOpenapi30},\n \"3_1\": {uri: \"https://spec.openapis.org/oas/3.1/schema-base\", validate: validateOpenapi31},\n} as const;\n\nexport const validator = async (openapi: {openapi: string; [key: string]: unknown}) => {\n const version = openapi.openapi.split(\".\").slice(0, 2).join(\"_\");\n const dialect = dialects[version as keyof typeof dialects];\n if (!dialect) {\n throw new Error(\"Not supported version.\\nopenapi version 3.0.0 >= version < 3.2.0\");\n }\n const output = (await dialect.validate(dialect.uri, openapi as unknown as Json, BASIC)) as OutputUnit;\n return {valid: output.valid, errors: errorExtractor(output)};\n};\n\nconst errorExtractor = (output: OutputUnit): Validate[] =>\n (output.errors ?? []).map((error) => ({\n keyword: error.keyword?.split(\"/\").pop() ?? \"\",\n rule: error.absoluteKeywordLocation?.split(\"#\")[1] ?? \"\",\n location: error.instanceLocation ?? \"\",\n }));\n"],"mappings":";AAAA,SAAQ,YAAY,yBAAwB;AAC5C,SAAQ,YAAY,yBAAwB;AAC5C,SAAQ,aAAY;AAiBpB,IAAM,WAAW;AAAA,EACf,OAAO,EAAC,KAAK,4CAA4C,UAAU,kBAAiB;AAAA,EACpF,OAAO,EAAC,KAAK,iDAAiD,UAAU,kBAAiB;AAC3F;AAEO,IAAM,YAAY,OAAO,YAAuD;AACrF,QAAM,UAAU,QAAQ,QAAQ,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AAC/D,QAAM,UAAU,SAAS,OAAgC;AACzD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,QAAM,SAAU,MAAM,QAAQ,SAAS,QAAQ,KAAK,SAA4B,KAAK;AACrF,SAAO,EAAC,OAAO,OAAO,OAAO,QAAQ,eAAe,MAAM,EAAC;AAC7D;AAEA,IAAM,iBAAiB,CAAC,YACrB,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC,WAAW;AAAA,EACpC,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,EAC5C,MAAM,MAAM,yBAAyB,MAAM,GAAG,EAAE,CAAC,KAAK;AAAA,EACtD,UAAU,MAAM,oBAAoB;AACtC,EAAE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automatons/validator",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"repository": "https://github.com/openapi-automatons/validator.git",
|
|
5
5
|
"author": "tanmen <yt.prog@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"packageManager": "yarn@1.22.22",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"module": "index.js",
|
|
11
|
+
"types": "index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"import": "./index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22"
|
|
20
|
+
},
|
|
7
21
|
"scripts": {
|
|
8
|
-
"prebuild": "depcheck
|
|
9
|
-
"build": "
|
|
10
|
-
"lint": "eslint src
|
|
11
|
-
"test": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"postversion": "cp package.json ../package.json"
|
|
22
|
+
"prebuild": "depcheck",
|
|
23
|
+
"build": "tsup && cp package.json README.md LICENSE dist",
|
|
24
|
+
"lint": "eslint src",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:coverage": "vitest run --coverage",
|
|
28
|
+
"prepare": "husky"
|
|
16
29
|
},
|
|
17
30
|
"keywords": [
|
|
18
31
|
"openapi",
|
|
@@ -20,34 +33,26 @@
|
|
|
20
33
|
"validator"
|
|
21
34
|
],
|
|
22
35
|
"dependencies": {
|
|
23
|
-
"@hyperjump/
|
|
36
|
+
"@hyperjump/browser": "^1",
|
|
37
|
+
"@hyperjump/json-schema": "^1"
|
|
24
38
|
},
|
|
25
39
|
"devDependencies": {
|
|
26
|
-
"@commitlint/cli": "^
|
|
27
|
-
"@commitlint/config-conventional": "^
|
|
28
|
-
"@
|
|
29
|
-
"@semantic-release/
|
|
30
|
-
"@semantic-release/
|
|
31
|
-
"@types/
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"eslint
|
|
41
|
-
"
|
|
42
|
-
"husky": "^8.0.3",
|
|
43
|
-
"jest": "^27.5.1",
|
|
44
|
-
"lint-staged": "^13.1.0",
|
|
45
|
-
"pinst": "^3.0.0",
|
|
46
|
-
"semantic-release": "^19.0.5",
|
|
47
|
-
"ts-jest": "^27.1.4",
|
|
48
|
-
"typescript": "^4.8.4",
|
|
49
|
-
"typesync": "^0.9.2",
|
|
50
|
-
"yarn-deduplicate": "^6.0.1"
|
|
40
|
+
"@commitlint/cli": "^21.0.2",
|
|
41
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
42
|
+
"@eslint/js": "^9.39.0",
|
|
43
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
44
|
+
"@semantic-release/git": "^10.0.1",
|
|
45
|
+
"@types/node": "^24.0.0",
|
|
46
|
+
"@vitest/coverage-v8": "^3.2.0",
|
|
47
|
+
"depcheck": "^1.4.7",
|
|
48
|
+
"eslint": "^9.39.0",
|
|
49
|
+
"husky": "^9.1.7",
|
|
50
|
+
"lint-staged": "^17.0.7",
|
|
51
|
+
"semantic-release": "^25.0.3",
|
|
52
|
+
"tsup": "^8.5.0",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"typescript-eslint": "^8.46.0",
|
|
55
|
+
"vitest": "^3.2.0"
|
|
51
56
|
},
|
|
52
57
|
"publishConfig": {
|
|
53
58
|
"access": "public"
|
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC"}
|