openapi-sync 1.0.21 → 1.0.23

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.
@@ -106,7 +106,7 @@ const getEndpointDetails = (path, method) => {
106
106
  };
107
107
  exports.getEndpointDetails = getEndpointDetails;
108
108
  const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
109
- let typeName = name ? `\t${name}${isRequired ? "" : "?"}: ` : "";
109
+ let typeName = name ? `\t"${name}"${isRequired ? "" : "?"}: ` : "";
110
110
  let type = "";
111
111
  if (schema) {
112
112
  if (schema.$ref) {
@@ -142,6 +142,25 @@ const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
142
142
  .map((v) => (0, exports.parseSchemaToType)(apiDoc, v, "", isRequired, options))
143
143
  .join("&")})`;
144
144
  }
145
+ else if (schema.items) {
146
+ type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
147
+ }
148
+ else if (schema.properties) {
149
+ //parse object key one at a time
150
+ const objKeys = Object.keys(schema.properties);
151
+ const requiredKeys = schema.required || [];
152
+ let typeCnt = "";
153
+ objKeys.forEach((key) => {
154
+ var _a;
155
+ typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
156
+ });
157
+ if (typeCnt.length > 0) {
158
+ type += `{\n${typeCnt}}`;
159
+ }
160
+ else {
161
+ type += "{[k: string]: any}";
162
+ }
163
+ }
145
164
  else if (schema.type) {
146
165
  if (schema.enum && schema.enum.length > 0) {
147
166
  if (schema.enum.length > 1)
@@ -158,36 +177,31 @@ const parseSchemaToType = (apiDoc, schema, name, isRequired, options) => {
158
177
  type += `number`;
159
178
  }
160
179
  else if (schema.type === "array") {
161
- if (schema.items) {
162
- type += `${(0, exports.parseSchemaToType)(apiDoc, schema.items, "", false, options)}[]`;
163
- }
164
- else {
165
- type += "any[]";
166
- }
180
+ //Since we would have already parsed the arrays keys above "schema.items" if it exists
181
+ type += "any[]";
182
+ /* if (schema.items) {
183
+ type += `${parseSchemaToType(
184
+ apiDoc,
185
+ schema.items,
186
+ "",
187
+ false,
188
+ options
189
+ )}[]`;
190
+ } else {
191
+ type += "any[]";
192
+ } */
167
193
  }
168
194
  else {
169
195
  type += schema.type;
170
196
  }
171
197
  }
172
198
  else if (schema.type === "object") {
173
- if (schema.properties) {
174
- //parse object key one at a time
175
- const objKeys = Object.keys(schema.properties);
176
- const requiredKeys = schema.required || [];
177
- let typeCnt = "";
178
- objKeys.forEach((key) => {
179
- var _a;
180
- typeCnt += `${(0, exports.parseSchemaToType)(apiDoc, (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key], key, requiredKeys.includes(key), options)}`;
181
- });
182
- if (typeCnt.length > 0) {
183
- type += `{\n${typeCnt}}`;
184
- }
185
- else {
186
- type += "object";
187
- }
199
+ //Since we would have already parsed the object keys above "schema.properties" if it exists
200
+ if (schema.additionalProperties) {
201
+ type += `{[k: string]: ${(0, exports.parseSchemaToType)(apiDoc, schema.additionalProperties, "", true, options)}}`;
188
202
  }
189
203
  else {
190
- type += "object";
204
+ type += "{[k: string]: any}";
191
205
  }
192
206
  }
193
207
  }
@@ -7,7 +7,14 @@ exports.resetState = exports.getState = exports.setState = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const dbPath = path_1.default.join(__dirname, "../", "../db.json");
10
- let state = require(dbPath);
10
+ let db = {};
11
+ try {
12
+ db = require(dbPath);
13
+ }
14
+ catch (error) {
15
+ db = {};
16
+ }
17
+ let state = db || {};
11
18
  const updateDB = (data) => {
12
19
  fs_1.default.writeFileSync(dbPath, JSON.stringify(data));
13
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
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",