openapi-ts-generator 5.220.7 → 5.221.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://ikemtz.visualstudio.com/CI%20CD/_apis/build/status/openapi-ts-generator?branchName=master)](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [![npm version](https://badge.fury.io/js/openapi-ts-generator.svg)](https://www.npmjs.com/package/openapi-ts-generator) [![npm downloads](https://img.shields.io/npm/dt/openapi-ts-generator)](https://www.npmjs.com/package/openapi-ts-generator) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=alert_status)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Issues](https://img.shields.io/github/issues-raw/ikemtz/OpenApi-TS-Generator)](https://github.com/ikemtz/openapi-ts-generator/issues) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=coverage)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=ncloc)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=security_rating)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator)
1
+ [![Build Status](https://ikemtz.visualstudio.com/CI%20CD/_apis/build/status/openapi-ts-generator?branchName=master)](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [![npm version](https://badge.fury.io/js/openapi-ts-generator.svg)](https://www.npmjs.com/package/openapi-ts-generator) [![npm downloads](https://img.shields.io/npm/dt/openapi-ts-generator)](https://www.npmjs.com/package/openapi-ts-generator) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=alert_status)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Issues](https://img.shields.io/github/issues-raw/ikemtz/OpenApi-TS-Generator)](https://github.com/ikemtz/openapi-ts-generator/issues) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=coverage)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=ncloc)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=security_rating)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![CodeQL](https://github.com/ikemtz/openapi-ts-generator/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ikemtz/openapi-ts-generator/actions/workflows/codeql-analysis.yml)
2
2
 
3
3
  # OpenApi-TS-Generator
4
4
 
@@ -57,7 +57,7 @@ var FormGroupGenerator = /** @class */ (function (_super) {
57
57
  if (value !== undefined && value !== null) {
58
58
  var hasMultipleValidators = prop.hasMultipleValidators;
59
59
  value = typeof value === 'string' ? "'".concat(value, "'") : value;
60
- return "".concat(!hasMultipleValidators ? ', ' : '', "Validators.").concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
60
+ return "Validators.".concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
61
61
  }
62
62
  return '';
63
63
  };
@@ -39,6 +39,7 @@ export interface IValueProperty {
39
39
  minimum?: number;
40
40
  description?: string;
41
41
  pattern?: string;
42
+ initialValue: string;
42
43
  }
43
44
  export interface IReferenceProperty {
44
45
  name: string;
@@ -49,4 +50,5 @@ export interface IReferenceProperty {
49
50
  isArray: boolean;
50
51
  required: boolean;
51
52
  isEnum?: boolean;
53
+ initialValue: string;
52
54
  }
@@ -17,6 +17,7 @@ export declare class OpenApiDocConverter {
17
17
  convertSchemaObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
18
18
  private convertValidator;
19
19
  convertArrayObjectToValuePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
20
+ getInitialValue(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): string;
20
21
  convertArrayObjectToReferencePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
21
22
  convertReferenceObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
22
23
  getValidatorCount(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): number;
@@ -114,9 +114,11 @@ var OpenApiDocConverter = /** @class */ (function () {
114
114
  OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
115
115
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
116
116
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
117
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
117
118
  return {
118
119
  required: required,
119
120
  name: propertyName,
121
+ initialValue: initialValue,
120
122
  isArray: false,
121
123
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
122
124
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
@@ -137,16 +139,40 @@ var OpenApiDocConverter = /** @class */ (function () {
137
139
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
138
140
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
139
141
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
142
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
140
143
  return {
141
144
  required: required,
145
+ typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
146
+ initialValue: initialValue,
142
147
  name: propertyName,
143
148
  isArray: true,
144
149
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
145
- typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
146
150
  hasMultipleValidators: false,
147
151
  hasValidators: validatorCount > 0,
148
152
  };
149
153
  };
154
+ OpenApiDocConverter.prototype.getInitialValue = function (propertyName, schemaWrapperInfo) {
155
+ var _a, _b;
156
+ var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
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) {
164
+ return 'null';
165
+ }
166
+ else if (typescriptType === 'Date') {
167
+ return 'new Date()';
168
+ }
169
+ else if (typescriptType === 'boolean') {
170
+ return 'false';
171
+ }
172
+ else {
173
+ return "''";
174
+ }
175
+ };
150
176
  OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (propertyName, schemaWrapperInfo) {
151
177
  return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
152
178
  };
@@ -155,9 +181,11 @@ var OpenApiDocConverter = /** @class */ (function () {
155
181
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
156
182
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
157
183
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
184
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
158
185
  return {
159
186
  required: required,
160
187
  name: propertyName,
188
+ initialValue: initialValue,
161
189
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
162
190
  referenceTypeName: this.parseRef(schemaWrapperInfo),
163
191
  typeScriptType: this.parseRef(schemaWrapperInfo),
@@ -188,10 +216,7 @@ var OpenApiDocConverter = /** @class */ (function () {
188
216
  else if (schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
189
217
  return 'Date';
190
218
  }
191
- if (!schemaWrapperInfo.propertySchemaObject.type) {
192
- throw new Error('Invalid Property Type');
193
- }
194
- return schemaWrapperInfo.propertySchemaObject.type;
219
+ return schemaWrapperInfo.propertySchemaObject.type || 'string';
195
220
  };
196
221
  OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
197
222
  var regexResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.220.7",
3
+ "version": "5.221.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",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
2
  /* istanbul ignore file */
2
3
  /**
3
4
  * This file is generated by the openapi-ts-generator
@@ -5,8 +6,9 @@
5
6
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
7
  * Do not edit.
7
8
  */
8
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
- import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR
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}}
10
12
 
11
13
  export function {{name}}FormGroupFac(): FormGroup {
12
14
  return new FormGroup({
@@ -19,9 +21,9 @@ export function {{name}}FormGroupFac(): FormGroup {
19
21
  {{/if}}
20
22
  {{else}}
21
23
  {{#if hasMultipleValidators}}
22
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>('', {validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
24
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
23
25
  {{else}}
24
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>(''{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
26
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
25
27
  {{/if}}
26
28
  {{/if}}
27
29
  {{/valueProperties}}
@@ -34,9 +36,9 @@ export function {{name}}FormGroupFac(): FormGroup {
34
36
  {{/if}}
35
37
  {{else}}
36
38
  {{#if hasMultipleValidators}}
37
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>('', { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
39
+ {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
38
40
  {{else}}
39
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>(''{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
41
+ {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
40
42
  {{/if}}
41
43
  {{/if}}
42
44
  {{/referenceProperties}}