openapi-sync 2.1.2 → 2.1.3

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/index.js CHANGED
@@ -16,12 +16,13 @@ exports.Init = void 0;
16
16
  const Openapi_sync_1 = __importDefault(require("./Openapi-sync"));
17
17
  const dotenv_1 = __importDefault(require("dotenv"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ const fs_1 = __importDefault(require("fs"));
19
20
  const state_1 = require("./Openapi-sync/state");
20
21
  dotenv_1.default.config();
21
22
  const rootUsingCwd = process.cwd();
22
23
  const Init = (options) => __awaiter(void 0, void 0, void 0, function* () {
23
24
  // Load config file
24
- let configJS, configJson;
25
+ let configJS, configJson, configTS;
25
26
  try {
26
27
  configJS = require(path_1.default.join(rootUsingCwd, "openapi.sync.js"));
27
28
  }
@@ -34,7 +35,23 @@ const Init = (options) => __awaiter(void 0, void 0, void 0, function* () {
34
35
  catch (e) {
35
36
  // console.log(e);
36
37
  }
37
- const config = configJS || configJson;
38
+ try {
39
+ // Check if TypeScript config file exists first
40
+ const tsConfigPath = path_1.default.join(rootUsingCwd, "openapi.sync.ts");
41
+ if (fs_1.default.existsSync(tsConfigPath)) {
42
+ // Register TypeScript loader before requiring the file
43
+ try {
44
+ require("esbuild-register");
45
+ }
46
+ catch (registerError) {
47
+ throw registerError;
48
+ }
49
+ // Now try to load TypeScript config
50
+ configTS = require(tsConfigPath);
51
+ }
52
+ }
53
+ catch (e) { }
54
+ const config = configTS || configJS || configJson;
38
55
  const apiNames = Object.keys(config.api);
39
56
  const refetchInterval = options &&
40
57
  "refetchInterval" in options &&
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ // TypeScript config file for openapi-sync
3
+ // To use this file, install a TypeScript loader:
4
+ // npm install --save-dev esbuild-register (recommended - fastest & lightest)
5
+ // or: npm install --save-dev tsx
6
+ // or: npm install --save-dev @swc/register
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const config = {
9
+ refetchInterval: 5000,
10
+ folder: "/inputed/path/",
11
+ api: {
12
+ example1: "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json",
13
+ example2: "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml",
14
+ },
15
+ server: 0,
16
+ types: {
17
+ name: {
18
+ prefix: "",
19
+ format: (source, data) => {
20
+ if (source === "shared") {
21
+ return `${data.name}`;
22
+ }
23
+ else if (source === "endpoint") {
24
+ return `${data.method.toLowerCase()}${data
25
+ .path.replace(/\//g, "_")
26
+ .replace(/{|}/g, "")}${data.code}${data.type}`;
27
+ }
28
+ },
29
+ },
30
+ doc: {
31
+ disable: true,
32
+ },
33
+ },
34
+ endpoints: {
35
+ value: {
36
+ replaceWords: [
37
+ {
38
+ replace: "/api/v\\d/",
39
+ with: "",
40
+ },
41
+ ],
42
+ includeServer: true,
43
+ type: "object",
44
+ },
45
+ name: {
46
+ prefix: "",
47
+ useOperationId: true,
48
+ format: ({ method, path, summary, operationId }) => {
49
+ if (path === "/")
50
+ return "root";
51
+ return path.replace(/\//g, "_").replace(/{|}/g, "");
52
+ },
53
+ },
54
+ doc: {
55
+ disable: false,
56
+ showCurl: true,
57
+ },
58
+ },
59
+ };
60
+ module.exports = config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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",
@@ -41,6 +41,7 @@
41
41
  "@types/js-yaml": "^4.0.9",
42
42
  "@types/lodash": "^4.17.7",
43
43
  "@types/node": "^22.1.0",
44
+ "esbuild-register": "^3.6.0",
44
45
  "typescript": "^5.5.4"
45
46
  },
46
47
  "dependencies": {