openapi-ts-generator 5.232.1 → 5.258.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.
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  export declare class EnumGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "EnumGenerator";
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  import { IHelperContext, PropertyType } from '../models/helper-context';
5
6
  export declare class FormGroupFactoryGenerator extends BaseGenerator<IEntity> {
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  export declare class FormGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "FormGenerator";
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  export declare class ModelPropertiesGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "ModelPropertiesGenerator";
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  export declare class ModelGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "ModelGenerator";
@@ -1,5 +1,6 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
- import { IEntity, ITemplateData } from '../models/template-data';
2
+ import { ITemplateData } from '../models/template-data';
3
+ import { IEntity } from '../models/entity';
3
4
  import { BaseGenerator } from './base.generator';
4
5
  export declare class TestObjectFactoryGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "TestObjectFactoryGenerator";
@@ -0,0 +1,18 @@
1
+ import { IReferenceProperty } from './reference-property';
2
+ import { IValueProperty } from './value-property';
3
+ import { IImportType } from './template-data';
4
+ export interface IEntity {
5
+ isEnum?: boolean;
6
+ enumValues: (string | {
7
+ key?: number;
8
+ name: string;
9
+ titleName: string;
10
+ })[];
11
+ name: string;
12
+ kebabCasedName: string;
13
+ camelSingularName: string;
14
+ description?: string;
15
+ importTypes: IImportType[];
16
+ valueProperties: IValueProperty[];
17
+ referenceProperties: IReferenceProperty[];
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,7 @@
1
1
  import { ILogger } from './logger';
2
- import { IEntity, IReferenceProperty, IValueProperty } from './template-data';
2
+ import { IEntity } from './entity';
3
+ import { IReferenceProperty } from './reference-property';
4
+ import { IValueProperty } from './value-property';
3
5
  export interface IGeneratorOptions {
4
6
  logger?: ILogger;
5
7
  outputPath: string;
@@ -1,4 +1,4 @@
1
- import { IEntity } from './template-data';
1
+ import { IEntity } from './entity';
2
2
  export interface IHelperContext {
3
3
  data: {
4
4
  root: IEntity;
@@ -1,3 +1,4 @@
1
- import { IEntity, IValueProperty } from './template-data';
1
+ import { IEntity } from './entity';
2
+ import { IValueProperty } from './value-property';
2
3
  export declare function nrsrxTypeFilterCallBack(val: IEntity, _i: number, _arr: IEntity[]): boolean;
3
4
  export declare function nrsrxValuePropertyTypeFilterCallBack(val: IValueProperty, _i: number, _arr: IValueProperty[]): boolean;
@@ -0,0 +1,20 @@
1
+ export interface IReferenceProperty {
2
+ name: string;
3
+ snakeCaseName: string;
4
+ referenceTypeName: string;
5
+ typeScriptType: string;
6
+ hasValidators: boolean;
7
+ isSameAsParentTypescriptType: boolean;
8
+ hasMultipleValidators: boolean;
9
+ maxItems?: number;
10
+ minItems?: number;
11
+ maxLength?: number;
12
+ minLength?: number;
13
+ maximum?: number;
14
+ minimum?: number;
15
+ isArray: boolean;
16
+ required: boolean;
17
+ isEnum?: boolean;
18
+ initialValue: string;
19
+ initialTestValue: string;
20
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,7 @@
1
1
  import { ReferenceObject, SchemaObject } from 'openapi3-ts';
2
2
  import { IGeneratorOptions } from './generator-options';
3
- import { IReferenceProperty, IValueProperty } from './template-data';
3
+ import { IReferenceProperty } from './reference-property';
4
+ import { IValueProperty } from './value-property';
4
5
  export declare class SchemaWrapperInfo {
5
6
  propertySchemaObject: SchemaObject;
6
7
  propertyReferenceObject: ReferenceObject;
@@ -1,3 +1,4 @@
1
+ import { IEntity } from './entity';
1
2
  export interface ITemplateData {
2
3
  entities?: IEntity[];
3
4
  paths: IPath[];
@@ -6,21 +7,6 @@ export interface IPath {
6
7
  tag: string;
7
8
  endpoint: string;
8
9
  }
9
- export interface IEntity {
10
- isEnum?: boolean;
11
- enumValues: (string | {
12
- key?: number;
13
- name: string;
14
- titleName: string;
15
- })[];
16
- name: string;
17
- kebabCasedName: string;
18
- camelSingularName: string;
19
- description?: string;
20
- importTypes: IImportType[];
21
- valueProperties: IValueProperty[];
22
- referenceProperties: IReferenceProperty[];
23
- }
24
10
  export interface IImportType {
25
11
  kebabCasedTypeName: string;
26
12
  name: string;
@@ -29,43 +15,3 @@ export interface IImportType {
29
15
  hasArrays: boolean;
30
16
  isSelfReferencing: boolean;
31
17
  }
32
- export interface IValueProperty {
33
- name: string;
34
- snakeCaseName: string;
35
- typeScriptType: string;
36
- isArray: boolean;
37
- hasValidators: boolean;
38
- hasMultipleValidators: boolean;
39
- required: boolean;
40
- maxLength?: number;
41
- minLength?: number;
42
- maximum?: number;
43
- minimum?: number;
44
- maxItems?: number;
45
- minItems?: number;
46
- email: boolean;
47
- description?: string;
48
- pattern?: string;
49
- initialValue: string;
50
- initialTestValue: string;
51
- }
52
- export interface IReferenceProperty {
53
- name: string;
54
- snakeCaseName: string;
55
- referenceTypeName: string;
56
- typeScriptType: string;
57
- hasValidators: boolean;
58
- isSameAsParentTypescriptType: boolean;
59
- hasMultipleValidators: boolean;
60
- maxItems?: number;
61
- minItems?: number;
62
- maxLength?: number;
63
- minLength?: number;
64
- maximum?: number;
65
- minimum?: number;
66
- isArray: boolean;
67
- required: boolean;
68
- isEnum?: boolean;
69
- initialValue: string;
70
- initialTestValue: string;
71
- }
@@ -0,0 +1,21 @@
1
+ export interface IValueProperty {
2
+ name: string;
3
+ snakeCaseName: string;
4
+ typeScriptType: string;
5
+ isArray: boolean;
6
+ hasValidators: boolean;
7
+ hasMultipleValidators: boolean;
8
+ required: boolean;
9
+ maxLength?: number;
10
+ minLength?: number;
11
+ maximum?: number;
12
+ minimum?: number;
13
+ maxItems?: number;
14
+ minItems?: number;
15
+ email: boolean;
16
+ uri: boolean;
17
+ description?: string;
18
+ pattern?: string;
19
+ initialValue: string;
20
+ initialTestValue: string;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,10 @@
1
1
  import { OpenAPIObject } from 'openapi3-ts';
2
2
  import { IGeneratorOptions } from './models/generator-options';
3
3
  import { SchemaWrapperInfo } from './models/schema-info';
4
- import { IEntity, IImportType, IPath, IReferenceProperty, ITemplateData, IValueProperty } from './models/template-data';
4
+ import { IImportType, IPath, ITemplateData } from './models/template-data';
5
+ import { IEntity } from './models/entity';
6
+ import { IReferenceProperty } from './models/reference-property';
7
+ import { IValueProperty } from './models/value-property';
5
8
  export declare class OpenApiDocConverter {
6
9
  private readonly options;
7
10
  private readonly apiDocument;
@@ -112,7 +112,7 @@ var OpenApiDocConverter = /** @class */ (function () {
112
112
  }
113
113
  };
114
114
  OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
115
- var _a;
115
+ var _a, _b;
116
116
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
117
117
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
118
118
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
@@ -130,6 +130,7 @@ var OpenApiDocConverter = /** @class */ (function () {
130
130
  maximum: schemaWrapperInfo.propertySchemaObject.maximum,
131
131
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
132
132
  email: ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email',
133
+ uri: ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'uri',
133
134
  minItems: schemaWrapperInfo.propertySchemaObject.minItems,
134
135
  maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
135
136
  description: schemaWrapperInfo.propertySchemaObject.description,
@@ -154,6 +155,7 @@ var OpenApiDocConverter = /** @class */ (function () {
154
155
  initialTestValue: initialTestValue,
155
156
  name: propertyName,
156
157
  email: false,
158
+ uri: false,
157
159
  isArray: true,
158
160
  snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
159
161
  hasMultipleValidators: false,
@@ -265,11 +267,13 @@ var OpenApiDocConverter = /** @class */ (function () {
265
267
  };
266
268
  };
267
269
  OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
268
- var _a;
270
+ var _a, _b;
269
271
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
270
272
  var email = ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email' || false;
273
+ var uri = ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'uri' || false;
271
274
  return (+required +
272
275
  +email +
276
+ +uri +
273
277
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
274
278
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
275
279
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.232.1",
3
+ "version": "5.258.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",
7
7
  "scripts": {
8
8
  "build": "npm run format && npm run lint && tsc && cp -rfv ./src/templates ./lib",
9
9
  "format": "prettier --write \"src/**/*.ts\"",
10
- "lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json",
10
+ "lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json && eslint . --ext .ts --output-file ./eslint-report.html --format html ",
11
11
  "link": "npm run build && cd lib && npm link && cd ..",
12
12
  "test": "npm run build && jest --collect-coverage",
13
13
  "prep:lib": "rm -rv ./lib/*.spec.* && rm -rv ./lib/**/*.spec.* && cp -v ./package.json ./lib/ && cp -v ./LICENSE ./lib/ && cp -v ./README.md ./lib/",
@@ -23,9 +23,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
23
23
  {{/if}}
24
24
  {{else}}
25
25
  {{#if hasMultipleValidators}}
26
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if email}}Validators.email, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
26
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if email}}Validators.email, {{/if}}{{#if uri}}Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?'), {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
27
27
  {{else}}
28
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{#if email}}Validators.email {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
28
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{#if email}}Validators.email {{/if}}{{#if uri}}Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?') {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
29
29
  {{/if}}
30
30
  {{/if}}
31
31
  {{/valueProperties}}
@@ -38,9 +38,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
38
38
  {{/if}}
39
39
  {{else if isEnum}}
40
40
  {{#if hasMultipleValidators}}
41
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
41
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
42
42
  {{else}}
43
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
43
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null| undefined{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
44
44
  {{/if}}
45
45
  {{else}}
46
46
  {{#if hasMultipleValidators}}
@@ -13,18 +13,18 @@ import { I{{name}}Form } from './{{kebabCasedTypeName}}.form';{{/if}}{{/unless}}
13
13
  export interface I{{name}}Form {
14
14
  {{#valueProperties}}
15
15
  {{#if isArray}}
16
- {{name}}?: FormArray<FormControl<{{typeScriptType}}>>;
16
+ {{name}}: FormArray<FormControl<{{typeScriptType}}>>;
17
17
  {{else}}
18
- {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
18
+ {{name}}: FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>;
19
19
  {{/if}}
20
20
  {{/valueProperties}}
21
21
  {{#referenceProperties}}
22
- {{#if isArray}}
23
- {{name}}?: FormArray<FormGroup<I{{typeScriptType}}Form>>;
22
+ {{#if isArray}}
23
+ {{name}}: FormArray<FormGroup<I{{typeScriptType}}Form>>;
24
24
  {{else if isEnum}}
25
- {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
25
+ {{name}}: FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>;
26
26
  {{else}}
27
- {{name}}?: FormGroup<I{{typeScriptType}}Form>;
27
+ {{name}}: FormGroup<I{{typeScriptType}}Form>;
28
28
  {{/if}}
29
29
  {{/referenceProperties}}
30
30
  }