openapi-sync 1.0.12 → 1.0.14

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 CHANGED
@@ -24,9 +24,9 @@ npx openapi-sync
24
24
 
25
25
  You can also add it as a script in your package.json for easy access:
26
26
 
27
- ```bash
27
+ ```json
28
28
  "scripts": {
29
- "api-sync": "openapi-sync",
29
+ "api-sync": "npx openapi-sync",
30
30
  }
31
31
  ```
32
32
 
package/bin/cli.js CHANGED
@@ -10,7 +10,7 @@ const argv = yargs(hideBin(process.argv))
10
10
  .option("refreshinterval", {
11
11
  alias: "ri",
12
12
  type: "number",
13
- description: "Interval at which to refretch specifiations",
13
+ description: "Interval at which to refetch specifiations",
14
14
  })
15
15
  .help().argv;
16
16
 
@@ -97,6 +97,21 @@ const OpenapiSync = (apiUrl, apiName, refetchInterval) => __awaiter(void 0, void
97
97
  }
98
98
  return typeCnt;
99
99
  };
100
+ const treatEndpointUrl = (endpointUrl) => {
101
+ var _a, _b;
102
+ if (((_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.replaceWords) &&
103
+ Array.isArray(config.endpoints.value.replaceWords)) {
104
+ let newEndpointUrl = endpointUrl;
105
+ config.endpoints.value.replaceWords.forEach((replaceWord, indx) => {
106
+ const regexp = new RegExp(replaceWord.replace, "g");
107
+ newEndpointUrl = newEndpointUrl.replace(regexp, replaceWord.with || "");
108
+ });
109
+ return newEndpointUrl;
110
+ }
111
+ else {
112
+ return endpointUrl;
113
+ }
114
+ };
100
115
  Object.keys(spec.paths || {}).forEach((endpointPath) => {
101
116
  const endpointSpec = spec.paths[endpointPath];
102
117
  const endpointMethods = Object.keys(endpointSpec);
@@ -118,6 +133,8 @@ const OpenapiSync = (apiUrl, apiName, refetchInterval) => __awaiter(void 0, void
118
133
  const params = endpoint.variables.map((v) => `${v}:string`).join(",");
119
134
  endpointUrl = `(${params})=> \`${endpointUrlTxt}\``;
120
135
  }
136
+ //treat endpoint url
137
+ endpointUrl = treatEndpointUrl(endpointUrl);
121
138
  // Add the endpoint url
122
139
  endpointsFileContent += `export const ${endpoint.name} = ${endpointUrl};
123
140
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "sync openapi variables",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",