@skmtc/core 0.0.796 → 0.0.797
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/esm/app/validate.d.ts +32 -0
- package/esm/app/validate.d.ts.map +1 -1
- package/esm/app/validate.js +32 -0
- package/esm/context/CoreContext.d.ts +137 -1
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +87 -0
- package/esm/dsl/constants.d.ts +28 -0
- package/esm/dsl/constants.d.ts.map +1 -1
- package/esm/dsl/constants.js +28 -0
- package/esm/oas/_helpers/parseDefault.d.ts +148 -0
- package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
- package/esm/oas/_helpers/parseDefault.js +128 -0
- package/esm/oas/_helpers/parseEnum.d.ts +124 -0
- package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
- package/esm/oas/_helpers/parseEnum.js +104 -0
- package/esm/oas/_helpers/parseExample.d.ts +107 -0
- package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
- package/esm/oas/_helpers/parseExample.js +87 -0
- package/esm/oas/_helpers/parseFormat.d.ts +154 -0
- package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
- package/esm/oas/_helpers/parseFormat.js +138 -0
- package/esm/oas/_helpers/parseNullable.d.ts +127 -0
- package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
- package/esm/oas/_helpers/parseNullable.js +113 -0
- package/esm/run/toV3JsonDocument.d.ts +90 -0
- package/esm/run/toV3JsonDocument.d.ts.map +1 -1
- package/esm/run/toV3JsonDocument.js +84 -0
- package/package.json +1 -1
- package/script/app/validate.d.ts +32 -0
- package/script/app/validate.d.ts.map +1 -1
- package/script/app/validate.js +32 -0
- package/script/context/CoreContext.d.ts +137 -1
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +87 -0
- package/script/dsl/constants.d.ts +28 -0
- package/script/dsl/constants.d.ts.map +1 -1
- package/script/dsl/constants.js +28 -0
- package/script/oas/_helpers/parseDefault.d.ts +148 -0
- package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
- package/script/oas/_helpers/parseDefault.js +128 -0
- package/script/oas/_helpers/parseEnum.d.ts +124 -0
- package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
- package/script/oas/_helpers/parseEnum.js +104 -0
- package/script/oas/_helpers/parseExample.d.ts +107 -0
- package/script/oas/_helpers/parseExample.d.ts.map +1 -1
- package/script/oas/_helpers/parseExample.js +87 -0
- package/script/oas/_helpers/parseFormat.d.ts +154 -0
- package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
- package/script/oas/_helpers/parseFormat.js +138 -0
- package/script/oas/_helpers/parseNullable.d.ts +127 -0
- package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
- package/script/oas/_helpers/parseNullable.js +113 -0
- package/script/run/toV3JsonDocument.d.ts +90 -0
- package/script/run/toV3JsonDocument.d.ts.map +1 -1
- package/script/run/toV3JsonDocument.js +84 -0
|
@@ -1,7 +1,97 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
2
|
import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
3
|
+
/**
|
|
4
|
+
* Union type representing any supported OpenAPI document version.
|
|
5
|
+
*
|
|
6
|
+
* SKMTC supports processing OpenAPI/Swagger documents from version 2.0 through 3.1,
|
|
7
|
+
* automatically converting them to OpenAPI 3.0 format for internal processing.
|
|
8
|
+
*/
|
|
3
9
|
type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
10
|
+
/**
|
|
11
|
+
* Parses a string into an OpenAPI document object.
|
|
12
|
+
*
|
|
13
|
+
* Automatically detects whether the input string is JSON or YAML format based on
|
|
14
|
+
* the content, then parses it into an OpenAPI document object. Supports all
|
|
15
|
+
* OpenAPI versions (2.0, 3.0.x, 3.1.x).
|
|
16
|
+
*
|
|
17
|
+
* @param schema - The OpenAPI document as a JSON or YAML string
|
|
18
|
+
* @returns Parsed OpenAPI document object
|
|
19
|
+
*
|
|
20
|
+
* @example Parsing JSON OpenAPI document
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const jsonSchema = `{
|
|
23
|
+
* "openapi": "3.0.0",
|
|
24
|
+
* "info": { "title": "My API", "version": "1.0.0" },
|
|
25
|
+
* "paths": {}
|
|
26
|
+
* }`;
|
|
27
|
+
* const document = stringToSchema(jsonSchema);
|
|
28
|
+
* console.log(document.info.title); // "My API"
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Parsing YAML OpenAPI document
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const yamlSchema = `
|
|
34
|
+
* openapi: 3.0.0
|
|
35
|
+
* info:
|
|
36
|
+
* title: My API
|
|
37
|
+
* version: 1.0.0
|
|
38
|
+
* paths: {}
|
|
39
|
+
* `;
|
|
40
|
+
* const document = stringToSchema(yamlSchema);
|
|
41
|
+
* console.log(document.info.title); // "My API"
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @throws {SyntaxError} If the JSON is malformed
|
|
45
|
+
* @throws {Error} If the YAML is malformed
|
|
46
|
+
*/
|
|
4
47
|
export declare const stringToSchema: (schema: string) => AnyOasDocument;
|
|
48
|
+
/**
|
|
49
|
+
* Converts any OpenAPI document version to OpenAPI 3.0 format.
|
|
50
|
+
*
|
|
51
|
+
* SKMTC processes all documents using OpenAPI 3.0 as the internal format.
|
|
52
|
+
* This function handles version detection and conversion from:
|
|
53
|
+
* - OpenAPI 3.0.x (returned as-is)
|
|
54
|
+
* - OpenAPI 3.1.x (downgraded to 3.0 with allOf transformations)
|
|
55
|
+
* - Swagger 2.0 (upgraded to OpenAPI 3.0)
|
|
56
|
+
*
|
|
57
|
+
* @param schema - The OpenAPI document to convert
|
|
58
|
+
* @returns Promise resolving to an OpenAPI 3.0 document
|
|
59
|
+
*
|
|
60
|
+
* @example Converting OpenAPI 3.1 to 3.0
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const openapi31Doc = {
|
|
63
|
+
* openapi: "3.1.0",
|
|
64
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
65
|
+
* paths: {}
|
|
66
|
+
* };
|
|
67
|
+
* const v3Doc = await toV3Document(openapi31Doc);
|
|
68
|
+
* console.log(v3Doc.openapi); // "3.0.3" (converted)
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Converting Swagger 2.0 to OpenAPI 3.0
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const swagger2Doc = {
|
|
74
|
+
* swagger: "2.0",
|
|
75
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
76
|
+
* paths: {}
|
|
77
|
+
* };
|
|
78
|
+
* const v3Doc = await toV3Document(swagger2Doc);
|
|
79
|
+
* console.log(v3Doc.openapi); // "3.0.0" (converted)
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example OpenAPI 3.0 passthrough
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const openapi30Doc = {
|
|
85
|
+
* openapi: "3.0.2",
|
|
86
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
87
|
+
* paths: {}
|
|
88
|
+
* };
|
|
89
|
+
* const v3Doc = await toV3Document(openapi30Doc);
|
|
90
|
+
* console.log(v3Doc === openapi30Doc); // true (same object)
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @throws {Error} If the document version is not recognized or supported
|
|
94
|
+
*/
|
|
5
95
|
export declare const toV3Document: (schema: AnyOasDocument) => Promise<OpenAPIV3.Document>;
|
|
6
96
|
export {};
|
|
7
97
|
//# sourceMappingURL=toV3JsonDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toV3JsonDocument.d.ts","sourceRoot":"","sources":["../../src/run/toV3JsonDocument.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAUtE,KAAK,cAAc,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;AAEpF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,cAM/C,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CA0BrF,CAAA"}
|
|
1
|
+
{"version":3,"file":"toV3JsonDocument.d.ts","sourceRoot":"","sources":["../../src/run/toV3JsonDocument.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAUtE;;;;;GAKG;AACH,KAAK,cAAc,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,cAM/C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CA0BrF,CAAA"}
|
|
@@ -9,6 +9,43 @@ const parse_js_1 = require("../deps/jsr.io/@std/yaml/1.0.9/parse.js");
|
|
|
9
9
|
const openapi_down_convert_1 = require("@apiture/openapi-down-convert");
|
|
10
10
|
const ts_pattern_1 = require("ts-pattern");
|
|
11
11
|
const swagger2openapi_1 = __importDefault(require("swagger2openapi"));
|
|
12
|
+
/**
|
|
13
|
+
* Parses a string into an OpenAPI document object.
|
|
14
|
+
*
|
|
15
|
+
* Automatically detects whether the input string is JSON or YAML format based on
|
|
16
|
+
* the content, then parses it into an OpenAPI document object. Supports all
|
|
17
|
+
* OpenAPI versions (2.0, 3.0.x, 3.1.x).
|
|
18
|
+
*
|
|
19
|
+
* @param schema - The OpenAPI document as a JSON or YAML string
|
|
20
|
+
* @returns Parsed OpenAPI document object
|
|
21
|
+
*
|
|
22
|
+
* @example Parsing JSON OpenAPI document
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const jsonSchema = `{
|
|
25
|
+
* "openapi": "3.0.0",
|
|
26
|
+
* "info": { "title": "My API", "version": "1.0.0" },
|
|
27
|
+
* "paths": {}
|
|
28
|
+
* }`;
|
|
29
|
+
* const document = stringToSchema(jsonSchema);
|
|
30
|
+
* console.log(document.info.title); // "My API"
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Parsing YAML OpenAPI document
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const yamlSchema = `
|
|
36
|
+
* openapi: 3.0.0
|
|
37
|
+
* info:
|
|
38
|
+
* title: My API
|
|
39
|
+
* version: 1.0.0
|
|
40
|
+
* paths: {}
|
|
41
|
+
* `;
|
|
42
|
+
* const document = stringToSchema(yamlSchema);
|
|
43
|
+
* console.log(document.info.title); // "My API"
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @throws {SyntaxError} If the JSON is malformed
|
|
47
|
+
* @throws {Error} If the YAML is malformed
|
|
48
|
+
*/
|
|
12
49
|
const stringToSchema = (schema) => {
|
|
13
50
|
if (schema.trimStart().startsWith('{')) {
|
|
14
51
|
return JSON.parse(schema);
|
|
@@ -18,6 +55,53 @@ const stringToSchema = (schema) => {
|
|
|
18
55
|
}
|
|
19
56
|
};
|
|
20
57
|
exports.stringToSchema = stringToSchema;
|
|
58
|
+
/**
|
|
59
|
+
* Converts any OpenAPI document version to OpenAPI 3.0 format.
|
|
60
|
+
*
|
|
61
|
+
* SKMTC processes all documents using OpenAPI 3.0 as the internal format.
|
|
62
|
+
* This function handles version detection and conversion from:
|
|
63
|
+
* - OpenAPI 3.0.x (returned as-is)
|
|
64
|
+
* - OpenAPI 3.1.x (downgraded to 3.0 with allOf transformations)
|
|
65
|
+
* - Swagger 2.0 (upgraded to OpenAPI 3.0)
|
|
66
|
+
*
|
|
67
|
+
* @param schema - The OpenAPI document to convert
|
|
68
|
+
* @returns Promise resolving to an OpenAPI 3.0 document
|
|
69
|
+
*
|
|
70
|
+
* @example Converting OpenAPI 3.1 to 3.0
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const openapi31Doc = {
|
|
73
|
+
* openapi: "3.1.0",
|
|
74
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
75
|
+
* paths: {}
|
|
76
|
+
* };
|
|
77
|
+
* const v3Doc = await toV3Document(openapi31Doc);
|
|
78
|
+
* console.log(v3Doc.openapi); // "3.0.3" (converted)
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Converting Swagger 2.0 to OpenAPI 3.0
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const swagger2Doc = {
|
|
84
|
+
* swagger: "2.0",
|
|
85
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
86
|
+
* paths: {}
|
|
87
|
+
* };
|
|
88
|
+
* const v3Doc = await toV3Document(swagger2Doc);
|
|
89
|
+
* console.log(v3Doc.openapi); // "3.0.0" (converted)
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example OpenAPI 3.0 passthrough
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const openapi30Doc = {
|
|
95
|
+
* openapi: "3.0.2",
|
|
96
|
+
* info: { title: "My API", version: "1.0.0" },
|
|
97
|
+
* paths: {}
|
|
98
|
+
* };
|
|
99
|
+
* const v3Doc = await toV3Document(openapi30Doc);
|
|
100
|
+
* console.log(v3Doc === openapi30Doc); // true (same object)
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @throws {Error} If the document version is not recognized or supported
|
|
104
|
+
*/
|
|
21
105
|
const toV3Document = async (schema) => {
|
|
22
106
|
return await (0, ts_pattern_1.match)(schema)
|
|
23
107
|
.with({ openapi: ts_pattern_1.P.string.startsWith('3.0') }, doc => doc)
|