openapi-ts-generator 5.221.5 → 5.223.2

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.
@@ -46,6 +46,7 @@ export interface IReferenceProperty {
46
46
  snakeCaseName: string;
47
47
  referenceTypeName: string;
48
48
  typeScriptType: string;
49
+ kebabCasedTypeScriptType: string;
49
50
  hasValidators: boolean;
50
51
  isArray: boolean;
51
52
  required: boolean;
@@ -155,14 +155,19 @@ var OpenApiDocConverter = /** @class */ (function () {
155
155
  var _a, _b;
156
156
  var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
157
157
  var isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
158
- var defaultValue = (schemaWrapperInfo.componentSchemaObject.default ||
159
- ((_b = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[schemaWrapperInfo.propertyReferenceObject['$ref']]) === null || _b === void 0 ? void 0 : _b.default));
160
- if (defaultValue) {
161
- return "'".concat(defaultValue.split(' ').pop(), "'");
162
- }
163
- else if (!isRequired) {
158
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
159
+ var refName = (((_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) || {})[propertyName].$ref;
160
+ var refObject = (((_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas) || {})[refName];
161
+ var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
162
+ if (!isRequired) {
164
163
  return 'null';
165
164
  }
165
+ else if (defaultValue && refObject.enum) {
166
+ return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
167
+ }
168
+ else if (defaultValue) {
169
+ return "'".concat(defaultValue.split(' ').pop(), "'");
170
+ }
166
171
  else if (typescriptType === 'Date') {
167
172
  return 'new Date()';
168
173
  }
@@ -185,13 +190,15 @@ var OpenApiDocConverter = /** @class */ (function () {
185
190
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
186
191
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
187
192
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
193
+ var typeName = this.parseRef(schemaWrapperInfo);
188
194
  return {
189
195
  required: required,
190
196
  name: propertyName,
191
197
  initialValue: initialValue,
192
198
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
193
- referenceTypeName: this.parseRef(schemaWrapperInfo),
194
- typeScriptType: this.parseRef(schemaWrapperInfo),
199
+ referenceTypeName: typeName,
200
+ typeScriptType: typeName,
201
+ kebabCasedTypeScriptType: (0, lodash_1.kebabCase)(typeName),
195
202
  isArray: false,
196
203
  isEnum: (propertySchema.enum || []).length > 0,
197
204
  hasValidators: validatorCount > 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.221.5",
3
+ "version": "5.223.2",
4
4
  "description": "Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -6,9 +6,9 @@
6
6
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
7
7
  * Do not edit.
8
8
  */
9
- import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR{{#if importTypes}}{{#importTypes}}{{#if isEnum}}
10
- import { {{name}} } from './{{kebabCasedTypeName}}.enum'; //NOSONAR{{else}}
11
- import { I{{name}} } from './{{kebabCasedTypeName}}.model'; //NOSONAR{{/if}}{{/importTypes}}{{/if}}
9
+ import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR{{#referenceProperties}}{{#unless isArray}}{{#if isEnum}}
10
+ import { {{typeScriptType}} } from './{{kebabCasedTypeScriptType}}.enum';{{else}}
11
+ import { I{{typeScriptType}} } from './{{kebabCasedTypeScriptType}}.model';{{/if}}{{/unless}}{{/referenceProperties}}
12
12
 
13
13
  export function {{name}}FormGroupFac(): FormGroup {
14
14
  return new FormGroup({