openapi-sync 2.0.1 → 2.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/db.json +1 -1
- package/dist/Openapi-sync/index.js +26 -21
- package/package.json +1 -1
- package/types.ts +2 -0
|
@@ -40,7 +40,7 @@ const apiClient = axios_1.default.create({
|
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
42
|
const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
var _a, _b, _c, _d, _e;
|
|
43
|
+
var _a, _b, _c, _d, _e, _f;
|
|
44
44
|
const specResponse = yield apiClient.get(apiUrl);
|
|
45
45
|
const redoclyConfig = yield (0, openapi_core_1.createConfig)({
|
|
46
46
|
extends: ["minimal"],
|
|
@@ -54,11 +54,11 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
54
54
|
});
|
|
55
55
|
const folderPath = path_1.default.join((config === null || config === void 0 ? void 0 : config.folder) || "", apiName);
|
|
56
56
|
const spec = lintResults.bundle.parsed;
|
|
57
|
-
const serverUrl = (_a = spec.servers[(config === null || config === void 0 ? void 0 : config.server) || 0]) === null ||
|
|
58
|
-
const typePrefix = typeof ((
|
|
57
|
+
const serverUrl = ((_b = (_a = spec === null || spec === void 0 ? void 0 : spec.servers) === null || _a === void 0 ? void 0 : _a[(config === null || config === void 0 ? void 0 : config.server) || 0]) === null || _b === void 0 ? void 0 : _b.url) || "";
|
|
58
|
+
const typePrefix = typeof ((_d = (_c = config === null || config === void 0 ? void 0 : config.types) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.prefix) === "string"
|
|
59
59
|
? config === null || config === void 0 ? void 0 : config.types.name.prefix
|
|
60
60
|
: "I";
|
|
61
|
-
const endpointPrefix = typeof ((
|
|
61
|
+
const endpointPrefix = typeof ((_f = (_e = config === null || config === void 0 ? void 0 : config.endpoints) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.prefix) === "string"
|
|
62
62
|
? config === null || config === void 0 ? void 0 : config.endpoints.name.prefix
|
|
63
63
|
: "";
|
|
64
64
|
const getSharedComponentName = (componentName, componentType) => {
|
|
@@ -446,7 +446,7 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
446
446
|
const endpointSpec = spec.paths[endpointPath];
|
|
447
447
|
const endpointMethods = Object.keys(endpointSpec);
|
|
448
448
|
endpointMethods.forEach((_method) => {
|
|
449
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
449
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
450
450
|
const method = _method;
|
|
451
451
|
const endpoint = (0, helpers_1.getEndpointDetails)(endpointPath, method);
|
|
452
452
|
const endpointUrlTxt = (((_b = (_a = config === null || config === void 0 ? void 0 : config.endpoints) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.includeServer) ? serverUrl : "") +
|
|
@@ -478,16 +478,6 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
478
478
|
//treat endpoint url
|
|
479
479
|
endpointUrl = treatEndpointUrl(endpointUrl);
|
|
480
480
|
const eSpec = endpointSpec[method];
|
|
481
|
-
let name = `${endpoint.name}`;
|
|
482
|
-
if ((_d = (_c = config === null || config === void 0 ? void 0 : config.endpoints) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.format) {
|
|
483
|
-
const formattedName = config === null || config === void 0 ? void 0 : config.endpoints.name.format({
|
|
484
|
-
method,
|
|
485
|
-
path: endpointPath,
|
|
486
|
-
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
487
|
-
});
|
|
488
|
-
if (formattedName)
|
|
489
|
-
name = formattedName;
|
|
490
|
-
}
|
|
491
481
|
let queryTypeCnt = "";
|
|
492
482
|
if (eSpec === null || eSpec === void 0 ? void 0 : eSpec.parameters) {
|
|
493
483
|
// create query parameters types
|
|
@@ -500,7 +490,7 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
500
490
|
if (queryTypeCnt) {
|
|
501
491
|
queryTypeCnt = `{\n${queryTypeCnt}}`;
|
|
502
492
|
let name = `${endpoint.name}Query`;
|
|
503
|
-
if ((
|
|
493
|
+
if ((_d = (_c = config === null || config === void 0 ? void 0 : config.types) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.format) {
|
|
504
494
|
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("endpoint", {
|
|
505
495
|
code: "",
|
|
506
496
|
type: "query",
|
|
@@ -521,7 +511,7 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
521
511
|
dtoTypeCnt = getBodySchemaType(requestBody);
|
|
522
512
|
if (dtoTypeCnt) {
|
|
523
513
|
let name = `${endpoint.name}DTO`;
|
|
524
|
-
if ((
|
|
514
|
+
if ((_f = (_e = config === null || config === void 0 ? void 0 : config.types) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.format) {
|
|
525
515
|
const formattedName = config === null || config === void 0 ? void 0 : config.types.name.format("endpoint", {
|
|
526
516
|
code: "",
|
|
527
517
|
type: "dto",
|
|
@@ -588,9 +578,9 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
588
578
|
? formatSecuritySpec(eSpec.security)
|
|
589
579
|
: "";
|
|
590
580
|
let doc = "";
|
|
591
|
-
if (!((
|
|
581
|
+
if (!((_h = (_g = config === null || config === void 0 ? void 0 : config.endpoints) === null || _g === void 0 ? void 0 : _g.doc) === null || _h === void 0 ? void 0 : _h.disable)) {
|
|
592
582
|
let curl = "";
|
|
593
|
-
if ((
|
|
583
|
+
if ((_k = (_j = config === null || config === void 0 ? void 0 : config.endpoints) === null || _j === void 0 ? void 0 : _j.doc) === null || _k === void 0 ? void 0 : _k.showCurl) {
|
|
594
584
|
// console.log("cirl data", {
|
|
595
585
|
// body: eSpec?.requestBody,
|
|
596
586
|
// bodyContent:
|
|
@@ -601,7 +591,7 @@ const OpenapiSync = (apiUrl, apiName, config, refetchInterval) => __awaiter(void
|
|
|
601
591
|
const headers = {};
|
|
602
592
|
let body = "";
|
|
603
593
|
let extras = "";
|
|
604
|
-
if ((
|
|
594
|
+
if ((_l = eSpec.requestBody) === null || _l === void 0 ? void 0 : _l.content) {
|
|
605
595
|
const contentTypes = Object.keys(eSpec.requestBody.content);
|
|
606
596
|
contentTypes.forEach((contentType) => {
|
|
607
597
|
// console.log("requestBody content", {
|
|
@@ -666,7 +656,7 @@ ${(0, curl_generator_1.CurlGenerator)({
|
|
|
666
656
|
doc = `/**${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.description) ? `\n* ${eSpec === null || eSpec === void 0 ? void 0 : eSpec.description} ` : ""}
|
|
667
657
|
* **Method**: \`${method.toUpperCase()}\`
|
|
668
658
|
* **Summary**: ${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary) || ""}
|
|
669
|
-
* **Tags**: [${((
|
|
659
|
+
* **Tags**: [${((_m = eSpec === null || eSpec === void 0 ? void 0 : eSpec.tags) === null || _m === void 0 ? void 0 : _m.join(", ")) || ""}]
|
|
670
660
|
* **OperationId**: ${(eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId) || ""} ${queryTypeCnt
|
|
671
661
|
? `\n * **Query**: ${(0, helpers_1.renderTypeRefMD)(queryTypeCnt)} `
|
|
672
662
|
: ""}${dtoTypeCnt ? `\n * **DTO**: ${(0, helpers_1.renderTypeRefMD)(dtoTypeCnt)} ` : ""}${responseTypeCnt
|
|
@@ -676,6 +666,21 @@ ${(0, curl_generator_1.CurlGenerator)({
|
|
|
676
666
|
: ""}${securitySpec ? `\n * **Security**: ${securitySpec}\n` : ""}${curl}
|
|
677
667
|
*/\n`;
|
|
678
668
|
}
|
|
669
|
+
let name = ((_p = (_o = config === null || config === void 0 ? void 0 : config.endpoints) === null || _o === void 0 ? void 0 : _o.name) === null || _p === void 0 ? void 0 : _p.useOperationId) &&
|
|
670
|
+
((_q = eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId) === null || _q === void 0 ? void 0 : _q.length) > 0
|
|
671
|
+
? eSpec.operationId
|
|
672
|
+
: `${endpoint.name}`;
|
|
673
|
+
console.log("endpoint.name", eSpec);
|
|
674
|
+
if ((_s = (_r = config === null || config === void 0 ? void 0 : config.endpoints) === null || _r === void 0 ? void 0 : _r.name) === null || _s === void 0 ? void 0 : _s.format) {
|
|
675
|
+
const formattedName = config === null || config === void 0 ? void 0 : config.endpoints.name.format({
|
|
676
|
+
method,
|
|
677
|
+
path: endpointPath,
|
|
678
|
+
summary: eSpec === null || eSpec === void 0 ? void 0 : eSpec.summary,
|
|
679
|
+
operationId: eSpec === null || eSpec === void 0 ? void 0 : eSpec.operationId,
|
|
680
|
+
});
|
|
681
|
+
if (formattedName)
|
|
682
|
+
name = formattedName;
|
|
683
|
+
}
|
|
679
684
|
// Add the endpoint url
|
|
680
685
|
endpointsFileContent += `${doc}export const ${endpointPrefix}${name} = ${endpointUrl};
|
|
681
686
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A developer-friendly tool designed to keep your API up-to-date by leveraging OpenAPI schemas. It automates the generation of endpoint URIs and type definitions, including shared types, directly from your OpenAPI specification.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|