openapi-ts-request 1.3.3 → 1.4.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.
@@ -171,13 +171,18 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
171
171
  return `(${allofList.join(' & ')})`;
172
172
  }
173
173
  if (schemaObject.type === 'object' || schemaObject.properties) {
174
+ if ((0, lodash_1.isObject)(schemaObject.additionalProperties)) {
175
+ const type = getDefaultType(schemaObject.additionalProperties, namespace, schemas);
176
+ return `Record<string, ${type}>`;
177
+ }
174
178
  if (!(0, lodash_1.keys)(schemaObject.properties).length) {
175
179
  return 'Record<string, unknown>';
176
180
  }
177
181
  return `{ ${(0, lodash_1.keys)(schemaObject.properties)
178
182
  .map((key) => {
179
- var _a, _b;
183
+ var _a;
180
184
  let required = false;
185
+ const property = (((_a = schemaObject.properties) === null || _a === void 0 ? void 0 : _a[key]) || {});
181
186
  if ((0, lodash_1.isBoolean)(schemaObject.required) && schemaObject.required) {
182
187
  required = true;
183
188
  }
@@ -185,8 +190,7 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
185
190
  schemaObject.required.includes(key)) {
186
191
  required = true;
187
192
  }
188
- if ('required' in (schemaObject.properties[key] || {}) &&
189
- ((_a = schemaObject.properties[key]) === null || _a === void 0 ? void 0 : _a.required)) {
193
+ if (property.required) {
190
194
  required = true;
191
195
  }
192
196
  /**
@@ -195,18 +199,29 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
195
199
  * 在后面进行格式化的时候会将正确的字符串转换为正常形式,
196
200
  * 错误的继续保留字符串。
197
201
  * */
198
- return `'${key}'${required ? '' : '?'}: ${getDefaultType((_b = schemaObject.properties) === null || _b === void 0 ? void 0 : _b[key], namespace)}; `;
202
+ return `
203
+ ${property.description ? `/** ${property.description} */` : ''}
204
+ '${key}'${required ? '' : '?'}: ${getDefaultType(property, namespace)}; `;
199
205
  })
200
206
  .join('')}}`;
201
207
  }
202
208
  return 'unknown';
203
209
  }
204
210
  function getDefaultFileTag(operationObject, apiPath) {
205
- return operationObject['x-swagger-router-controller']
206
- ? [operationObject['x-swagger-router-controller']]
207
- : operationObject.tags || [operationObject.operationId] || [
208
- apiPath.replace('/', '').split('/')[1],
209
- ];
211
+ let lastTags = [];
212
+ if (operationObject['x-swagger-router-controller']) {
213
+ lastTags = [operationObject['x-swagger-router-controller']];
214
+ }
215
+ else if (!(0, lodash_1.isEmpty)(operationObject.tags)) {
216
+ lastTags = operationObject.tags;
217
+ }
218
+ else if (operationObject.operationId) {
219
+ lastTags = [operationObject.operationId];
220
+ }
221
+ else {
222
+ lastTags = [apiPath.replace('/', '').split('/')[1]];
223
+ }
224
+ return lastTags;
210
225
  }
211
226
  function findDuplicateTypeNames(arr) {
212
227
  const counts = (0, lodash_1.countBy)(arr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",