@devbie/apits 0.0.0-stage → 1.0.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/README.md +89 -2
- package/bin/apits +4 -0
- package/dist/cjs/core/cli.d.ts +29 -0
- package/dist/cjs/core/cli.js +396 -0
- package/dist/cjs/core/generator.d.ts +44 -0
- package/dist/cjs/core/generator.js +301 -0
- package/dist/cjs/core/writeRequestClient.d.ts +2 -0
- package/dist/cjs/core/writeRequestClient.js +93 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/types.d.ts +330 -0
- package/dist/cjs/types.js +90 -0
- package/dist/cjs/utils/console.d.ts +16 -0
- package/dist/cjs/utils/console.js +79 -0
- package/dist/cjs/utils/getOutputPath.d.ts +5 -0
- package/dist/cjs/utils/getOutputPath.js +43 -0
- package/dist/cjs/utils/helpers.d.ts +65 -0
- package/dist/cjs/utils/helpers.js +166 -0
- package/dist/cjs/utils/openApiToInterfaces.d.ts +14 -0
- package/dist/cjs/utils/openApiToInterfaces.js +229 -0
- package/dist/cjs/utils/spinner.d.ts +15 -0
- package/dist/cjs/utils/spinner.js +69 -0
- package/dist/cjs/utils/utils.d.ts +56 -0
- package/dist/cjs/utils/utils.js +355 -0
- package/dist/cjs/utils/vtilsLite.d.ts +55 -0
- package/dist/cjs/utils/vtilsLite.js +123 -0
- package/dist/esm/core/cli.d.mts +29 -0
- package/dist/esm/core/cli.mjs +713 -0
- package/dist/esm/core/generator.d.mts +44 -0
- package/dist/esm/core/generator.mjs +463 -0
- package/dist/esm/core/writeRequestClient.d.mts +2 -0
- package/dist/esm/core/writeRequestClient.mjs +54 -0
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/types.d.mts +330 -0
- package/dist/esm/types.mjs +94 -0
- package/dist/esm/utils/console.d.mts +16 -0
- package/dist/esm/utils/console.mjs +65 -0
- package/dist/esm/utils/getOutputPath.d.mts +5 -0
- package/dist/esm/utils/getOutputPath.mjs +12 -0
- package/dist/esm/utils/helpers.d.mts +65 -0
- package/dist/esm/utils/helpers.mjs +226 -0
- package/dist/esm/utils/openApiToInterfaces.d.mts +14 -0
- package/dist/esm/utils/openApiToInterfaces.mjs +326 -0
- package/dist/esm/utils/spinner.d.mts +15 -0
- package/dist/esm/utils/spinner.mjs +58 -0
- package/dist/esm/utils/utils.d.mts +56 -0
- package/dist/esm/utils/utils.mjs +545 -0
- package/dist/esm/utils/vtilsLite.d.mts +55 -0
- package/dist/esm/utils/vtilsLite.mjs +142 -0
- package/package.json +68 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/helpers.ts
|
|
20
|
+
var helpers_exports = {};
|
|
21
|
+
__export(helpers_exports, {
|
|
22
|
+
FileData: () => FileData,
|
|
23
|
+
asyncFnArrayOrderRun: () => asyncFnArrayOrderRun,
|
|
24
|
+
defineConfig: () => defineConfig,
|
|
25
|
+
parseRequestData: () => parseRequestData,
|
|
26
|
+
prepare: () => prepare
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
29
|
+
function defineConfig(config) {
|
|
30
|
+
const configs = config instanceof Array ? config : [config];
|
|
31
|
+
const final = configs.map((item) => {
|
|
32
|
+
const client = "client" in item ? item.client : item.clientImportTemplate ? false : true;
|
|
33
|
+
return {
|
|
34
|
+
output: "src/api",
|
|
35
|
+
client,
|
|
36
|
+
...item
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
return final;
|
|
40
|
+
}
|
|
41
|
+
var FileData = class {
|
|
42
|
+
/**
|
|
43
|
+
* File data helper class, unified file upload for web, mini-program and other platforms.
|
|
44
|
+
*
|
|
45
|
+
* @param originalFileData Original file data
|
|
46
|
+
* @param options If using internal getFormData, options will be used by it
|
|
47
|
+
*/
|
|
48
|
+
constructor(originalFileData, options) {
|
|
49
|
+
this.originalFileData = originalFileData;
|
|
50
|
+
this.options = options;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get original file data.
|
|
54
|
+
*
|
|
55
|
+
* @returns Original file data
|
|
56
|
+
*/
|
|
57
|
+
getOriginalFileData() {
|
|
58
|
+
return this.originalFileData;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get options.
|
|
62
|
+
*/
|
|
63
|
+
getOptions() {
|
|
64
|
+
return this.options;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function parseRequestData(requestData) {
|
|
68
|
+
const result = {
|
|
69
|
+
data: {},
|
|
70
|
+
fileData: {}
|
|
71
|
+
};
|
|
72
|
+
if (requestData != null) {
|
|
73
|
+
if (typeof requestData === "object" && !Array.isArray(requestData)) {
|
|
74
|
+
Object.keys(requestData).forEach((key) => {
|
|
75
|
+
if (requestData[key] && requestData[key] instanceof FileData) {
|
|
76
|
+
result.fileData[key] = requestData[key].getOriginalFileData();
|
|
77
|
+
} else {
|
|
78
|
+
result.data[key] = requestData[key];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
result.data = requestData;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function prepare(requestConfig, requestData) {
|
|
88
|
+
let requestPath = requestConfig.path;
|
|
89
|
+
const { data, fileData } = parseRequestData(requestData);
|
|
90
|
+
const dataIsObject = data != null && typeof data === "object" && !Array.isArray(data);
|
|
91
|
+
if (dataIsObject) {
|
|
92
|
+
if (Array.isArray(requestConfig.paramNames) && requestConfig.paramNames.length > 0) {
|
|
93
|
+
Object.keys(data).forEach((key) => {
|
|
94
|
+
if (requestConfig.paramNames.indexOf(key) >= 0) {
|
|
95
|
+
requestPath = requestPath.replace(new RegExp(`\\{${key}\\}`, "g"), data[key]).replace(new RegExp(`/:${key}(?=/|$)`, "g"), `/${data[key]}`);
|
|
96
|
+
delete data[key];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
let queryString = "";
|
|
101
|
+
if (Array.isArray(requestConfig.queryNames) && requestConfig.queryNames.length > 0) {
|
|
102
|
+
Object.keys(data).forEach((key) => {
|
|
103
|
+
if (requestConfig.queryNames.indexOf(key) >= 0) {
|
|
104
|
+
if (data[key] != null) {
|
|
105
|
+
queryString += `${queryString ? "&" : ""}${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
|
|
106
|
+
}
|
|
107
|
+
delete data[key];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (queryString) {
|
|
112
|
+
requestPath += `${requestPath.indexOf("?") > -1 ? "&" : "?"}${queryString}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const allData = {
|
|
116
|
+
...dataIsObject ? data : {},
|
|
117
|
+
...fileData
|
|
118
|
+
};
|
|
119
|
+
const getFormData = () => {
|
|
120
|
+
const useNativeFormData = typeof FormData !== "undefined";
|
|
121
|
+
const useNodeFormData = !useNativeFormData && // https://github.com/fjc0k/vtils/blob/master/src/utils/inNodeJS.ts
|
|
122
|
+
typeof global === "object" && typeof global.process === "object" && typeof global.process.versions === "object" && global.process.versions.node != null;
|
|
123
|
+
const UniFormData = useNativeFormData ? FormData : useNodeFormData ? (
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
125
|
+
require("form-data")
|
|
126
|
+
) : void 0;
|
|
127
|
+
if (!UniFormData) {
|
|
128
|
+
throw new Error("FormData is not supported in the current environment");
|
|
129
|
+
}
|
|
130
|
+
const formData = new UniFormData();
|
|
131
|
+
Object.keys(data).forEach((key) => {
|
|
132
|
+
formData.append(key, data[key]);
|
|
133
|
+
});
|
|
134
|
+
Object.keys(fileData).forEach((key) => {
|
|
135
|
+
const options = requestData[key].getOptions();
|
|
136
|
+
formData.append(key, fileData[key], useNativeFormData ? options == null ? void 0 : options.filename : options);
|
|
137
|
+
});
|
|
138
|
+
return formData;
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
...requestConfig,
|
|
142
|
+
path: requestPath,
|
|
143
|
+
rawData: requestData,
|
|
144
|
+
data,
|
|
145
|
+
hasFileData: fileData && Object.keys(fileData).length > 0,
|
|
146
|
+
fileData,
|
|
147
|
+
allData,
|
|
148
|
+
getFormData
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
var asyncFnArrayOrderRun = async (fns, results) => {
|
|
152
|
+
if (fns.length) {
|
|
153
|
+
const res = await fns[0]();
|
|
154
|
+
const res1 = await asyncFnArrayOrderRun(fns.slice(1), [...results || [], res]);
|
|
155
|
+
return res1;
|
|
156
|
+
}
|
|
157
|
+
return results || [];
|
|
158
|
+
};
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
FileData,
|
|
162
|
+
asyncFnArrayOrderRun,
|
|
163
|
+
defineConfig,
|
|
164
|
+
parseRequestData,
|
|
165
|
+
prepare
|
|
166
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import { Interface } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert an OpenAPI 3.x document into the internal `Interface[]` format.
|
|
5
|
+
*
|
|
6
|
+
* Reads OAS3 directly — no intermediate Swagger 2.0 `openapi3Format` step,
|
|
7
|
+
* no YApi platform fields (`_id`/`project_id`/`catid`/`add_time`/`up_time`),
|
|
8
|
+
* no module-level mutable state.
|
|
9
|
+
*
|
|
10
|
+
* @param data OpenAPI 3.x document (object or JSON string)
|
|
11
|
+
*/
|
|
12
|
+
export declare function openApiToInterfaces(data: OpenAPIV3.Document | string): Promise<{
|
|
13
|
+
interfaces: Interface[];
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/openApiToInterfaces.ts
|
|
30
|
+
var openApiToInterfaces_exports = {};
|
|
31
|
+
__export(openApiToInterfaces_exports, {
|
|
32
|
+
openApiToInterfaces: () => openApiToInterfaces
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(openApiToInterfaces_exports);
|
|
35
|
+
var import_types = require("../types.js");
|
|
36
|
+
var import_vtilsLite = require("./vtilsLite.js");
|
|
37
|
+
var conso = __toESM(require("./console.js"));
|
|
38
|
+
function handlePath(p) {
|
|
39
|
+
if (p === "/")
|
|
40
|
+
return p;
|
|
41
|
+
if (p.charAt(0) !== "/")
|
|
42
|
+
p = `/${p}`;
|
|
43
|
+
if (p.charAt(p.length - 1) === "/")
|
|
44
|
+
p = p.slice(0, -1);
|
|
45
|
+
return p;
|
|
46
|
+
}
|
|
47
|
+
function resolveRef(ref, root) {
|
|
48
|
+
if (!ref || typeof ref !== "string" || !ref.startsWith("#/") || ref.length <= 2)
|
|
49
|
+
return null;
|
|
50
|
+
const parts = ref.slice(2).split("/").filter(Boolean);
|
|
51
|
+
let node = root;
|
|
52
|
+
for (const part of parts) {
|
|
53
|
+
if (node == null)
|
|
54
|
+
return null;
|
|
55
|
+
node = node[part];
|
|
56
|
+
}
|
|
57
|
+
return node ?? null;
|
|
58
|
+
}
|
|
59
|
+
function isRef(obj) {
|
|
60
|
+
return obj != null && typeof obj === "object" && "$ref" in obj;
|
|
61
|
+
}
|
|
62
|
+
function handleRequestBody(requestBody, api) {
|
|
63
|
+
if (!requestBody || typeof requestBody !== "object")
|
|
64
|
+
return;
|
|
65
|
+
const content = requestBody.content || {};
|
|
66
|
+
const jsonContent = content["application/json"];
|
|
67
|
+
if (jsonContent && jsonContent.schema) {
|
|
68
|
+
api.req_body_other = JSON.stringify(jsonContent.schema, null, 2);
|
|
69
|
+
api.req_body_type = import_types.RequestBodyType.json;
|
|
70
|
+
api.req_body_is_json_schema = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const multipartContent = content["multipart/form-data"];
|
|
74
|
+
const formContent = multipartContent || content["application/x-www-form-urlencoded"];
|
|
75
|
+
if (formContent && formContent.schema) {
|
|
76
|
+
const schema = formContent.schema;
|
|
77
|
+
if (isRef(schema))
|
|
78
|
+
return;
|
|
79
|
+
const required = schema.required || [];
|
|
80
|
+
const props = schema.properties || {};
|
|
81
|
+
for (const name of Object.keys(props)) {
|
|
82
|
+
const prop = props[name] || {};
|
|
83
|
+
const arrayItems = Array.isArray(prop.items) ? prop.items[0] : prop.items;
|
|
84
|
+
const isFileArray = prop.type === "array" && arrayItems && arrayItems.format === "binary";
|
|
85
|
+
const isFile = prop.format === "binary" || isFileArray;
|
|
86
|
+
api.req_body_form.push({
|
|
87
|
+
name,
|
|
88
|
+
type: isFile ? import_types.RequestFormItemType.file : import_types.RequestFormItemType.text,
|
|
89
|
+
desc: prop.description || "",
|
|
90
|
+
example: "",
|
|
91
|
+
required: required.indexOf(name) > -1 ? import_types.Required.true : import_types.Required.false,
|
|
92
|
+
...isFileArray ? { isArray: true } : {},
|
|
93
|
+
...Array.isArray(prop.enum) && prop.enum.length ? { enum: prop.enum } : {}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
|
|
97
|
+
api.req_body_additional = schema.additionalProperties;
|
|
98
|
+
}
|
|
99
|
+
api.req_body_type = import_types.RequestBodyType.form;
|
|
100
|
+
api.req_body_multipart = !!multipartContent;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function handleResponse(responses) {
|
|
104
|
+
if (!responses || typeof responses !== "object")
|
|
105
|
+
return { body: "", hasSchema: false };
|
|
106
|
+
const codes = Object.keys(responses);
|
|
107
|
+
if (codes.length === 0)
|
|
108
|
+
return { body: "", hasSchema: false };
|
|
109
|
+
const curCode = codes.indexOf("200") > -1 ? "200" : codes[0];
|
|
110
|
+
const res = responses[curCode];
|
|
111
|
+
if (!res || typeof res !== "object") {
|
|
112
|
+
return { body: "", hasSchema: false };
|
|
113
|
+
}
|
|
114
|
+
if (isRef(res))
|
|
115
|
+
return { body: "", hasSchema: false };
|
|
116
|
+
const content = res.content;
|
|
117
|
+
if (content && typeof content === "object") {
|
|
118
|
+
const mediaType = content["application/json"] || content["application/hal+json"] || content["*/*"];
|
|
119
|
+
if (mediaType && mediaType.schema) {
|
|
120
|
+
return {
|
|
121
|
+
body: JSON.stringify(mediaType.schema, null, 2),
|
|
122
|
+
hasSchema: true
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (res.description)
|
|
127
|
+
return { body: res.description, hasSchema: false };
|
|
128
|
+
return { body: "", hasSchema: false };
|
|
129
|
+
}
|
|
130
|
+
function handleOpenApiOperation(operation, path, method, originTags, root) {
|
|
131
|
+
const api = {
|
|
132
|
+
title: operation.summary || path,
|
|
133
|
+
path: handlePath(path),
|
|
134
|
+
method: method.toUpperCase(),
|
|
135
|
+
req_params: [],
|
|
136
|
+
req_body_form: [],
|
|
137
|
+
req_query: [],
|
|
138
|
+
req_body_type: import_types.RequestBodyType.raw,
|
|
139
|
+
req_body_is_json_schema: false,
|
|
140
|
+
req_body_other: "",
|
|
141
|
+
res_body_type: import_types.ResponseBodyType.raw,
|
|
142
|
+
res_body_is_json_schema: false,
|
|
143
|
+
res_body: ""
|
|
144
|
+
};
|
|
145
|
+
api.catname = null;
|
|
146
|
+
if (Array.isArray(operation.tags)) {
|
|
147
|
+
for (const tag of operation.tags) {
|
|
148
|
+
if (/v[0-9.]+/.test(tag))
|
|
149
|
+
continue;
|
|
150
|
+
if (originTags.length > 0 && (0, import_vtilsLite.find)(originTags, (item) => item.name === tag)) {
|
|
151
|
+
api.catname = tag;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (originTags.length === 0) {
|
|
155
|
+
api.catname = tag;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(operation.parameters)) {
|
|
161
|
+
for (let param of operation.parameters) {
|
|
162
|
+
if (isRef(param)) {
|
|
163
|
+
param = resolveRef(param.$ref, root);
|
|
164
|
+
}
|
|
165
|
+
if (!param || typeof param !== "object")
|
|
166
|
+
continue;
|
|
167
|
+
const p = param;
|
|
168
|
+
const paramObj = {
|
|
169
|
+
name: p.name,
|
|
170
|
+
desc: p.description || "",
|
|
171
|
+
type: p.schema ? p.schema.type : p.type,
|
|
172
|
+
required: p.required ? import_types.Required.true : import_types.Required.false,
|
|
173
|
+
example: ""
|
|
174
|
+
};
|
|
175
|
+
switch (p.in) {
|
|
176
|
+
case "path":
|
|
177
|
+
api.req_params.push(paramObj);
|
|
178
|
+
break;
|
|
179
|
+
case "query":
|
|
180
|
+
api.req_query.push(paramObj);
|
|
181
|
+
break;
|
|
182
|
+
case "header":
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const reqBody = operation.requestBody;
|
|
190
|
+
handleRequestBody(isRef(reqBody) ? void 0 : reqBody, api);
|
|
191
|
+
const { body: resBody, hasSchema } = handleResponse(operation.responses);
|
|
192
|
+
api.res_body = resBody;
|
|
193
|
+
if (hasSchema) {
|
|
194
|
+
api.res_body_type = import_types.ResponseBodyType.json;
|
|
195
|
+
api.res_body_is_json_schema = true;
|
|
196
|
+
} else if (resBody) {
|
|
197
|
+
api.res_body_type = import_types.ResponseBodyType.raw;
|
|
198
|
+
}
|
|
199
|
+
return api;
|
|
200
|
+
}
|
|
201
|
+
async function openApiToInterfaces(data) {
|
|
202
|
+
if (typeof data === "string" && data) {
|
|
203
|
+
try {
|
|
204
|
+
data = JSON.parse(data);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
conso.error(`Failed to parse JSON: ${e.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const doc = data;
|
|
210
|
+
const tags = Array.isArray(doc.tags) ? doc.tags : [];
|
|
211
|
+
const interfaces = [];
|
|
212
|
+
(0, import_vtilsLite.each)(doc.paths || {}, (pathItem, path) => {
|
|
213
|
+
delete pathItem.parameters;
|
|
214
|
+
(0, import_vtilsLite.each)(pathItem, (operation, method) => {
|
|
215
|
+
if (!operation || typeof operation !== "object")
|
|
216
|
+
return;
|
|
217
|
+
try {
|
|
218
|
+
const iface = handleOpenApiOperation(operation, path, method, tags, doc);
|
|
219
|
+
interfaces.push(iface);
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
return { interfaces };
|
|
225
|
+
}
|
|
226
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
227
|
+
0 && (module.exports = {
|
|
228
|
+
openApiToInterfaces
|
|
229
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Ora } from "ora";
|
|
2
|
+
declare class Spin {
|
|
3
|
+
spinnerInstance: Ora;
|
|
4
|
+
constructor();
|
|
5
|
+
clear(): void;
|
|
6
|
+
start(text?: string): void;
|
|
7
|
+
succeed(text?: string): void;
|
|
8
|
+
fail(text?: string): void;
|
|
9
|
+
render(): void;
|
|
10
|
+
frame(): void;
|
|
11
|
+
info(text?: string): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const spinnerInstance: Spin;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/spinner.ts
|
|
30
|
+
var spinner_exports = {};
|
|
31
|
+
__export(spinner_exports, {
|
|
32
|
+
spinnerInstance: () => spinnerInstance
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(spinner_exports);
|
|
35
|
+
var import_ora = __toESM(require("ora"));
|
|
36
|
+
var Spin = class {
|
|
37
|
+
constructor() {
|
|
38
|
+
this.spinnerInstance = (0, import_ora.default)();
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this.spinnerInstance.clear();
|
|
42
|
+
}
|
|
43
|
+
start(text) {
|
|
44
|
+
this.spinnerInstance.start(text);
|
|
45
|
+
}
|
|
46
|
+
succeed(text) {
|
|
47
|
+
this.spinnerInstance.succeed(text);
|
|
48
|
+
}
|
|
49
|
+
fail(text) {
|
|
50
|
+
this.spinnerInstance.fail(text);
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
this.spinnerInstance.render();
|
|
54
|
+
}
|
|
55
|
+
frame() {
|
|
56
|
+
this.spinnerInstance.frame();
|
|
57
|
+
}
|
|
58
|
+
info(text) {
|
|
59
|
+
this.spinnerInstance.info(text);
|
|
60
|
+
}
|
|
61
|
+
stop() {
|
|
62
|
+
this.spinnerInstance.stop();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var spinnerInstance = new Spin();
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
spinnerInstance
|
|
69
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Interface } from "../types.js";
|
|
2
|
+
import { JSONSchema4 } from "json-schema";
|
|
3
|
+
/**
|
|
4
|
+
* Process a JSON Schema in place.
|
|
5
|
+
*
|
|
6
|
+
* @param jsonSchema JSON Schema to process
|
|
7
|
+
* @returns the processed JSON Schema
|
|
8
|
+
*/
|
|
9
|
+
export declare function processJsonSchema<T extends JSONSchema4>(jsonSchema: T): T;
|
|
10
|
+
/**
|
|
11
|
+
* Pre-process a schema before compiling it to TypeScript.
|
|
12
|
+
*
|
|
13
|
+
* Handles edge cases such as empty enums and normalizes OpenAPI 3.x
|
|
14
|
+
* `nullable: true` into the JSON Schema union-null form
|
|
15
|
+
* (`type: [T, 'null']`) so json-schema-to-typescript emits `T | null`.
|
|
16
|
+
* Component schemas reach the compiler through this preprocessor instead of
|
|
17
|
+
* `processJsonSchema`, and jstt silently ignores the OpenAPI `nullable`
|
|
18
|
+
* keyword. Every node here is a fresh copy, so the source document is never
|
|
19
|
+
* mutated.
|
|
20
|
+
*
|
|
21
|
+
* @param schema input JSON Schema
|
|
22
|
+
* @returns normalized JSON Schema (fresh copy, source is not mutated)
|
|
23
|
+
*/
|
|
24
|
+
export declare function preprocessSchema(schema: JSONSchema4): JSONSchema4;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a TypeScript type definition from a JSON Schema object.
|
|
27
|
+
*
|
|
28
|
+
* @param jsonSchema JSON Schema object
|
|
29
|
+
* @param typeName type name
|
|
30
|
+
* @returns TypeScript type definition
|
|
31
|
+
*/
|
|
32
|
+
export declare function jsonSchemaToTsCode(jsonSchema: JSONSchema4, typeName: string): Promise<string>;
|
|
33
|
+
export declare function getRequestDataJsonSchema(interfaceInfo: Interface): JSONSchema4;
|
|
34
|
+
export declare function getResponseDataJsonSchema(interfaceInfo: Interface): JSONSchema4;
|
|
35
|
+
/**
|
|
36
|
+
* Format generated code with prettier.
|
|
37
|
+
*
|
|
38
|
+
* When the output file path is known, the consumer project's own prettier
|
|
39
|
+
* config is resolved from it (resolveConfig walks up from the file location),
|
|
40
|
+
* so generated code lands clean under the consumer's `prettier --check`. When
|
|
41
|
+
* the consumer has no config, pure prettier defaults are used, mirroring what
|
|
42
|
+
* the consumer's own prettier would produce. `filepath` is always set so
|
|
43
|
+
* prettier infers the parser from the extension and applies any matching
|
|
44
|
+
* `overrides` from the consumer config.
|
|
45
|
+
*
|
|
46
|
+
* @param content code to format
|
|
47
|
+
* @param filePath output file path used to resolve the consumer config
|
|
48
|
+
* @returns formatted code
|
|
49
|
+
* @see https://prettier.io/docs/en/options.html
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatContent(content: string, filePath?: string): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Generate the banner comment placed at the top of every generated file.
|
|
54
|
+
* @returns banner comment
|
|
55
|
+
*/
|
|
56
|
+
export declare function topNotesContent(): string;
|