openapi-ts-request 1.3.4 → 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.
@@ -180,8 +180,9 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
180
180
  }
181
181
  return `{ ${(0, lodash_1.keys)(schemaObject.properties)
182
182
  .map((key) => {
183
- var _a, _b;
183
+ var _a;
184
184
  let required = false;
185
+ const property = (((_a = schemaObject.properties) === null || _a === void 0 ? void 0 : _a[key]) || {});
185
186
  if ((0, lodash_1.isBoolean)(schemaObject.required) && schemaObject.required) {
186
187
  required = true;
187
188
  }
@@ -189,8 +190,7 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
189
190
  schemaObject.required.includes(key)) {
190
191
  required = true;
191
192
  }
192
- if ('required' in (schemaObject.properties[key] || {}) &&
193
- ((_a = schemaObject.properties[key]) === null || _a === void 0 ? void 0 : _a.required)) {
193
+ if (property.required) {
194
194
  required = true;
195
195
  }
196
196
  /**
@@ -199,18 +199,29 @@ function getDefaultType(schemaObject, namespace = '', schemas) {
199
199
  * 在后面进行格式化的时候会将正确的字符串转换为正常形式,
200
200
  * 错误的继续保留字符串。
201
201
  * */
202
- 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)}; `;
203
205
  })
204
206
  .join('')}}`;
205
207
  }
206
208
  return 'unknown';
207
209
  }
208
210
  function getDefaultFileTag(operationObject, apiPath) {
209
- return operationObject['x-swagger-router-controller']
210
- ? [operationObject['x-swagger-router-controller']]
211
- : operationObject.tags || [operationObject.operationId] || [
212
- apiPath.replace('/', '').split('/')[1],
213
- ];
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;
214
225
  }
215
226
  function findDuplicateTypeNames(arr) {
216
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.4",
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",