openapi-ts-generator 5.221.3 → 5.222.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;
@@ -152,12 +152,15 @@ var OpenApiDocConverter = /** @class */ (function () {
152
152
  };
153
153
  };
154
154
  OpenApiDocConverter.prototype.getInitialValue = function (propertyName, schemaWrapperInfo) {
155
- var _a, _b;
155
+ var _a;
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) {
158
+ var refObject = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[schemaWrapperInfo.propertyReferenceObject['$ref']];
159
+ var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
160
+ if (defaultValue && refObject.enum) {
161
+ return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
162
+ }
163
+ else if (defaultValue) {
161
164
  return "'".concat(defaultValue.split(' ').pop(), "'");
162
165
  }
163
166
  else if (!isRequired) {
@@ -185,13 +188,15 @@ var OpenApiDocConverter = /** @class */ (function () {
185
188
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
186
189
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
187
190
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
191
+ var typeName = this.parseRef(schemaWrapperInfo);
188
192
  return {
189
193
  required: required,
190
194
  name: propertyName,
191
195
  initialValue: initialValue,
192
196
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
193
- referenceTypeName: this.parseRef(schemaWrapperInfo),
194
- typeScriptType: this.parseRef(schemaWrapperInfo),
197
+ referenceTypeName: typeName,
198
+ typeScriptType: typeName,
199
+ kebabCasedTypeScriptType: (0, lodash_1.kebabCase)(typeName),
195
200
  isArray: false,
196
201
  isEnum: (propertySchema.enum || []).length > 0,
197
202
  hasValidators: validatorCount > 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.221.3",
3
+ "version": "5.222.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({
@@ -17,7 +17,7 @@ export function {{name}}FormGroupFac(): FormGroup {
17
17
  {{#if hasMultipleValidators}}
18
18
  {{name}}: new FormControl([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
19
19
  {{else}}
20
- {{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} }{{/if}}),
20
+ {{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
21
21
  {{/if}}
22
22
  {{else}}
23
23
  {{#if hasMultipleValidators}}
@@ -30,9 +30,9 @@ export function {{name}}FormGroupFac(): FormGroup {
30
30
  {{#referenceProperties}}
31
31
  {{#if isArray}}
32
32
  {{#if hasMultipleValidators}}
33
- {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
33
+ {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
34
34
  {{else}}
35
- {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
35
+ {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
36
36
  {{/if}}
37
37
  {{else}}
38
38
  {{#if hasMultipleValidators}}