openapi-ts-generator 5.220.9 → 5.221.3

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
 
@@ -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,43 @@ 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 if (typescriptType === 'number') {
173
+ return '0';
174
+ }
175
+ else {
176
+ return "''";
177
+ }
178
+ };
150
179
  OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (propertyName, schemaWrapperInfo) {
151
180
  return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
152
181
  };
@@ -155,9 +184,11 @@ var OpenApiDocConverter = /** @class */ (function () {
155
184
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
156
185
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
157
186
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
187
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
158
188
  return {
159
189
  required: required,
160
190
  name: propertyName,
191
+ initialValue: initialValue,
161
192
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
162
193
  referenceTypeName: this.parseRef(schemaWrapperInfo),
163
194
  typeScriptType: this.parseRef(schemaWrapperInfo),
@@ -188,10 +219,7 @@ var OpenApiDocConverter = /** @class */ (function () {
188
219
  else if (schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
189
220
  return 'Date';
190
221
  }
191
- if (!schemaWrapperInfo.propertySchemaObject.type) {
192
- throw new Error('Invalid Property Type');
193
- }
194
- return schemaWrapperInfo.propertySchemaObject.type;
222
+ return schemaWrapperInfo.propertySchemaObject.type || 'string';
195
223
  };
196
224
  OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
197
225
  var regexResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.220.9",
3
+ "version": "5.221.3",
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,7 +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
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}}>({{#if required}}''{{else}}null{{/if}}, { 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 required}}''{{else}}null{{/if}}{{#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}}>({{#if required}}''{{else}}null{{/if}}, { 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 required}}''{{else}}null{{/if}}{{#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}}