Skip to content

Commit 23ce60a

Browse files
Issue #12 - Added support for multi level arrays in API Schemes
1 parent d207791 commit 23ce60a

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/models/model-attributes.model.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export class ModelAttributessModel {
1010
isOptional: boolean = true;
1111
isArray: boolean;
1212

13+
/**
14+
* Must be increased for each array level
15+
*/
16+
arrayLevels: number = 0;
17+
1318
private _typeURI;
1419
private _model: ModelModel;
1520

@@ -45,6 +50,14 @@ export class ModelAttributessModel {
4550
this._model = model;
4651
}
4752

53+
54+
/**
55+
* Return a fake array with "arrayLevels" elements to print it in mustache.js
56+
*/
57+
get arrayLevelsRepeater(): any[] {
58+
return new Array(this.arrayLevels).fill(true);
59+
}
60+
4861
constructor(name: string) {
4962
this.name = name;
5063
}

src/services/parsers/open-api-v3/components-parser.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class ComponentsParserService extends ParserBaseService {
3939
this.modelStore.add(enumInstance);
4040
} else {
4141
console.error(`ERROR: ${modelName} not a correct Schema`);
42+
if ((rawModel as any)?.type === 'array') {
43+
console.error(`ERROR: ARRAY not supported on COMPONENTS SCHEMA`);
44+
}
4245
}
4346

4447
if (elementRef) {

src/services/parsers/open-api-v3/parser-base.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export abstract class ParserBaseService {
209209
if (rawAttribute.type === 'array') {
210210
console.group(`${attrName} is an array`);
211211
attribute.isArray = true;
212+
attribute.arrayLevels++;
212213
this.fillAttribute(attribute, rawAttribute.items, defaultName);
213214
console.groupEnd();
214215
} else if (rawAttribute.enum) {

templates/angular2/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class {{ name }} {
3232
{{/deprecated}}
3333
*/
3434
{{/hasComments}}
35-
{{name}}{{#isOptional}}?{{/isOptional}}: {{type}}{{#isArray}}[]{{/isArray}}{{#default}} = {{default}}{{/default}};
35+
{{name}}{{#isOptional}}?{{/isOptional}}: {{type}}{{#isArray
36+
}}{{#arrayLevelsRepeater}}[]{{/arrayLevelsRepeater}}{{
37+
/isArray}}{{#default}} = {{default}}{{/default}};
3638

3739
{{/attributes}}
3840
}

0 commit comments

Comments
 (0)