Skip to content

Commit 785b742

Browse files
author
Etienne
committed
[fix] string arrays not being taken as arrays
1 parent 0e486ae commit 785b742

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

dist/utils/GenerateType.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ const GenerateType = async (attribute, writeStream, typeIntfName, hardTypes, inc
4848
}
4949
return create.property(attribute.key, type.string, attribute.required === false && DeclarationFlags.Optional);
5050
}
51+
// handle arrays
52+
if (attribute.array === true) {
53+
const types = {
54+
integer: type.number,
55+
double: type.number,
56+
string: type.string,
57+
boolean: type.boolean,
58+
};
59+
return create.property(attribute.key, type.array(type[types[attribute.type]]), attribute.required === false && DeclarationFlags.Optional);
60+
}
5161
// handle strings
5262
if (attribute.type === 'string') {
5363
return create.property(attribute.key, type.string, attribute.required === false && DeclarationFlags.Optional);
5464
}
55-
// handle arrays
56-
if (attribute.array === true) {
57-
return create.property(attribute.key, type.array(type.any), attribute.required === false && DeclarationFlags.Optional);
58-
}
5965
// handle integer & double
6066
if (attribute.type === 'integer' || attribute.type === 'double') {
6167
return create.property(attribute.key, type.number, attribute.required === false && DeclarationFlags.Optional);

src/utils/GenerateType.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,22 @@ const GenerateType = async (attribute: Attribute, writeStream: WriteStream, type
7878
return create.property(attribute.key, type.string, attribute.required === false && DeclarationFlags.Optional);
7979
}
8080

81+
// handle arrays
82+
if (attribute.array === true) {
83+
const types = {
84+
integer: type.number,
85+
double: type.number,
86+
string: type.string,
87+
boolean: type.boolean,
88+
};
89+
return create.property(attribute.key, type.array(type[types[attribute.type]]), attribute.required === false && DeclarationFlags.Optional);
90+
}
91+
8192
// handle strings
8293
if (attribute.type === 'string') {
8394
return create.property(attribute.key, type.string, attribute.required === false && DeclarationFlags.Optional);
8495
}
8596

86-
// handle arrays
87-
if (attribute.array === true) {
88-
return create.property(attribute.key, type.array(type.any), attribute.required === false && DeclarationFlags.Optional);
89-
}
90-
9197
// handle integer & double
9298
if (attribute.type === 'integer' || attribute.type === 'double') {
9399
return create.property(attribute.key, type.number, attribute.required === false && DeclarationFlags.Optional);

tests/models/dbName.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface LibraryBooksDocument extends LibraryBooksType, Models.Document
2020
export interface LibraryOthersBooksType {
2121
Xdrdh?: number;
2222
books?: LibraryBooksType;
23+
stringArray?: string[];
2324
}
2425

2526
export interface LibraryOthersBooksDocument extends LibraryOthersBooksType, Models.Document {

tests/models/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface BooksDocument extends BooksType, Models.Document {
2020
export interface OthersBooksType {
2121
Xdrdh?: number;
2222
books?: BooksType;
23+
stringArray?: string[];
2324
}
2425

2526
export interface OthersBooksDocument extends OthersBooksType, Models.Document {

tests/models/hardTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface BooksDocument extends BooksType, Models.Document {
2424
export interface OthersBooksType {
2525
Xdrdh?: number;
2626
books?: BooksType;
27+
stringArray?: string[];
2728
}
2829

2930
export interface OthersBooksDocument extends OthersBooksType, Models.Document {

0 commit comments

Comments
 (0)