• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

electrode-io / electrode-native / 7581

24 Apr 2026 09:20AM UTC coverage: 56.608% (-11.2%) from 67.856%
7581

push

Azure Pipelines

web-flow
Merge pull request #1924 from electrode-io/npm-security-audit-fix

3600 of 7762 branches covered (46.38%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1659 existing lines in 112 files now uncovered.

9425 of 15247 relevant lines covered (61.82%)

523.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.3
/ern-api-gen/src/InlineModelResolver.ts
1
import ArrayModel from './models/ArrayModel';
2✔
2
import ModelImpl from './models//ModelImpl';
2✔
3
import RefModel from './models/RefModel';
2✔
4
import { BodyParameter } from './models/parameters';
2✔
5
import {
2✔
6
  ArrayProperty,
7
  MapProperty,
8
  ObjectProperty,
9
  RefProperty,
10
} from './models/properties';
11
import Json from './java/Json';
2✔
12
import { isNotEmptySet, newHashMap } from './java/javaUtil';
2✔
13

14
function hasProperties(obj) {
15
  if (obj == null) {
×
16
    return false;
×
17
  }
18
  return isNotEmptySet(obj.getProperties());
×
19
}
20

21
export default class InlineModelResolver {
2✔
22
  public addedModels = newHashMap();
115✔
23
  public generatedSignature = newHashMap();
115✔
24
  public skipMatches = false;
115✔
25
  public swagger;
26

27
  public flatten(swagger) {
28
    this.swagger = swagger;
115✔
29
    if (swagger.getDefinitions() == null) {
115✔
30
      swagger.setDefinitions(newHashMap());
37✔
31
    }
32
    const paths = swagger.getPaths();
108✔
33
    const models = swagger.getDefinitions();
108✔
34
    if (paths != null) {
108!
35
      for (const path of paths) {
108✔
36
        const pathname = path.path;
597✔
37
        for (const operation of path.getOperations()) {
597✔
38
          const parameters = operation.getParameters();
821✔
39

40
          if (isNotEmptySet(parameters)) {
821✔
41
            for (const parameter of parameters) {
690✔
42
              if (parameter != null && parameter instanceof BodyParameter) {
1,000✔
43
                const bp: any = parameter;
269✔
44
                if (bp.getSchema() != null) {
269!
45
                  const model = bp.getSchema();
269✔
46
                  if (model != null && model instanceof ModelImpl) {
269✔
47
                    const obj = model;
41✔
48
                    if (obj.getType() == null || 'object' === obj.getType()) {
41!
UNCOV
49
                      if (isNotEmptySet(obj.getProperties())) {
×
50
                        this.flattenProperties(obj.getProperties(), pathname);
×
51
                        const modelName = this.resolveModelName(
×
52
                          obj.getTitle(),
53
                          bp.getName(),
54
                        );
55
                        bp.setSchema(new RefModel(modelName));
×
56
                        this.addGenerated(modelName, model);
×
57
                        swagger.addDefinition(modelName, model);
×
58
                      }
59
                    }
60
                  } else if (model != null && model instanceof ArrayModel) {
228✔
61
                    const am = model;
68✔
62
                    const inner = am.getItems();
68✔
63
                    if (inner != null && inner instanceof ObjectProperty) {
68!
64
                      const op: any = inner;
×
65
                      if (isNotEmptySet(op.getProperties())) {
×
66
                        this.flattenProperties(op.getProperties(), pathname);
×
67
                        const modelName = this.resolveModelName(
×
68
                          op.getTitle(),
69
                          bp.getName(),
70
                        );
71
                        const innerModel = this.modelFromProperty(
×
72
                          op,
73
                          modelName,
74
                        );
75
                        const existing = this.matchGenerated(innerModel);
×
76
                        if (existing != null) {
×
77
                          am.setItems(new RefProperty(existing));
×
78
                        } else {
79
                          am.setItems(new RefProperty(modelName));
×
80
                          this.addGenerated(modelName, innerModel);
×
81
                          swagger.addDefinition(modelName, innerModel);
×
82
                        }
83
                      }
84
                    }
85
                  }
86
                }
87
              }
88
            }
89
          }
90
          const responses = operation.getResponses();
821✔
91
          if (isNotEmptySet(responses)) {
821✔
92
            for (const [key, response] of responses) {
744✔
93
              const property = response.getSchema();
1,246✔
94
              if (property == null) {
1,246✔
95
                continue;
777✔
96
              }
97
              if (property instanceof ObjectProperty) {
469!
98
                const op: any = property;
×
99
                if (hasProperties(op)) {
×
100
                  const modelName = this.resolveModelName(
×
101
                    op.getTitle(),
102
                    'inline_response_' + key,
103
                  );
104
                  const model = this.modelFromProperty(op, modelName);
×
105
                  const existing = this.matchGenerated(model);
×
106
                  if (existing != null) {
×
107
                    response.setSchema(new RefProperty(existing));
×
108
                  } else {
109
                    response.setSchema(new RefProperty(modelName));
×
110
                    this.addGenerated(modelName, model);
×
111
                    swagger.addDefinition(modelName, model);
×
112
                  }
113
                }
114
              } else if (property instanceof ArrayProperty) {
469✔
115
                const ap = property;
112✔
116
                const inner = ap.getItems();
112✔
117
                if (inner != null && inner instanceof ObjectProperty) {
112!
118
                  const op: any = inner;
×
119
                  if (hasProperties(op)) {
×
120
                    this.flattenProperties(op.getProperties(), pathname);
×
121
                    const modelName = this.resolveModelName(
×
122
                      op.getTitle(),
123
                      'inline_response_' + key,
124
                    );
125
                    const innerModel = this.modelFromProperty(op, modelName);
×
126
                    const existing = this.matchGenerated(innerModel);
×
127
                    if (existing != null) {
×
128
                      ap.setItems(new RefProperty(existing));
×
129
                    } else {
130
                      ap.setItems(new RefProperty(modelName));
×
131
                      this.addGenerated(modelName, innerModel);
×
132
                      swagger.addDefinition(modelName, innerModel);
×
133
                    }
134
                  }
135
                }
136
              } else if (property instanceof MapProperty) {
357✔
137
                const mp = property;
27✔
138
                const innerProperty = mp.getAdditionalProperties();
27✔
139
                if (
27!
140
                  innerProperty != null &&
54✔
141
                  innerProperty instanceof ObjectProperty
142
                ) {
143
                  const op: any = innerProperty;
×
144
                  if (hasProperties(op)) {
×
145
                    this.flattenProperties(op.getProperties(), pathname);
×
146
                    const modelName = this.resolveModelName(
×
147
                      op.getTitle(),
148
                      'inline_response_' + key,
149
                    );
150
                    const innerModel = this.modelFromProperty(op, modelName);
×
151
                    const existing = this.matchGenerated(innerModel);
×
152
                    if (existing != null) {
×
153
                      mp.setAdditionalProperties(new RefProperty(existing));
×
154
                    } else {
155
                      mp.setAdditionalProperties(new RefProperty(modelName));
×
156
                      this.addGenerated(modelName, innerModel);
×
157
                      swagger.addDefinition(modelName, innerModel);
×
158
                    }
159
                  }
160
                }
161
              }
162
            }
163
          }
164
        }
165
      }
166
    }
167
    if (models != null) {
108✔
168
      for (const [modelName, model] of models) {
71✔
169
        if (model == null) {
255!
170
          continue;
×
171
        }
172
        if (model instanceof ModelImpl) {
255✔
173
          this.flattenProperties(model.getProperties(), modelName);
248✔
174
        } else if (model instanceof ArrayModel) {
7!
175
          const m = model;
×
176
          const inner = m.getItems();
×
177
          if (inner != null && inner instanceof ObjectProperty) {
×
178
            const op: any = inner;
×
179
            if (isNotEmptySet(op.getProperties())) {
×
180
              const innerModelName = this.uniqueName(modelName + '_inner');
×
181
              const innerModel = this.modelFromProperty(op, innerModelName);
×
182
              const existing = this.matchGenerated(innerModel);
×
183
              if (existing == null) {
×
184
                swagger.addDefinition(innerModelName, innerModel);
×
185
                this.addGenerated(innerModelName, innerModel);
×
186
                m.setItems(new RefProperty(innerModelName));
×
187
              } else {
188
                m.setItems(new RefProperty(existing));
×
189
              }
190
            }
191
          }
192
        }
193
      }
194
    }
195
  }
196

197
  public resolveModelName(title, key) {
198
    if (title == null) {
×
199
      return this.uniqueName(key);
×
200
    } else {
201
      return this.uniqueName(title);
×
202
    }
203
  }
204

205
  public matchGenerated(model) {
206
    if (this.skipMatches) {
×
207
      return null;
×
208
    }
209
    const json = Json.pretty(model);
×
210
    if (this.generatedSignature.containsKey(json)) {
×
211
      return this.generatedSignature.get(json);
×
212
    }
213
    return null;
×
214
  }
215

216
  public addGenerated(name, model) {
217
    this.generatedSignature.put(Json.pretty(model), name);
×
218
  }
219

220
  public uniqueName(key) {
221
    let count = 0;
×
222
    key = key.replace(new RegExp('[^a-z_\\.A-Z0-9 ]', 'g'), '');
×
223
    while (true) {
×
224
      let name = key;
×
225
      if (count > 0) {
×
226
        name = key + '_' + count;
×
227
      }
228
      if (this.swagger.getDefinitions() == null) {
×
229
        return name;
×
230
      } else if (!this.swagger.getDefinitions().containsKey(name)) {
×
231
        return name;
×
232
      }
233
      count += 1;
×
234
    }
235
    return key;
×
236
  }
237

238
  public flattenProperties(properties, path) {
239
    if (properties == null) {
248!
240
      return;
×
241
    }
242
    const propsToUpdate = newHashMap();
248✔
243
    const modelsToAdd = newHashMap();
248✔
244
    for (const [key, property] of properties) {
248✔
245
      if (property instanceof ObjectProperty && hasProperties(property)) {
1,110!
246
        const modelName = this.uniqueName(path + '_' + key);
×
247
        const model = this.modelFromProperty(property, modelName);
×
248
        const existing = this.matchGenerated(model);
×
249
        if (existing != null) {
×
250
          propsToUpdate.put(key, new RefProperty(existing));
×
251
        } else {
252
          propsToUpdate.put(key, new RefProperty(modelName));
×
253
          modelsToAdd.put(modelName, model);
×
254
          this.addGenerated(modelName, model);
×
255
          this.swagger.addDefinition(modelName, model);
×
256
        }
257
      } else if (property instanceof ArrayProperty) {
1,110✔
258
        const ap = property;
65✔
259
        const inner = ap.getItems();
65✔
260
        if (inner instanceof ObjectProperty) {
65!
261
          const op: any = inner;
×
262
          if (hasProperties(op)) {
×
263
            this.flattenProperties(op.getProperties(), path);
×
264
            const modelName = this.uniqueName(path + '_' + key);
×
265
            const innerModel = this.modelFromProperty(op, modelName);
×
266
            const existing = this.matchGenerated(innerModel);
×
267
            if (existing != null) {
×
268
              ap.setItems(new RefProperty(existing));
×
269
            } else {
270
              ap.setItems(new RefProperty(modelName));
×
271
              this.addGenerated(modelName, innerModel);
×
272
              this.swagger.addDefinition(modelName, innerModel);
×
273
            }
274
          }
275
        }
276
      } else if (property instanceof MapProperty) {
1,045!
277
        const mp = property;
×
278
        const inner = mp.getAdditionalProperties();
×
279
        if (inner != null && inner instanceof ObjectProperty) {
×
280
          const op: any = inner;
×
281
          if (hasProperties(op)) {
×
282
            this.flattenProperties(op.getProperties(), path);
×
283
            const modelName = this.uniqueName(path + '_' + key);
×
284
            const innerModel = this.modelFromProperty(op, modelName);
×
285
            const existing = this.matchGenerated(innerModel);
×
286
            if (existing != null) {
×
287
              mp.setAdditionalProperties(new RefProperty(existing));
×
288
            } else {
289
              mp.setAdditionalProperties(new RefProperty(modelName));
×
290
              this.addGenerated(modelName, innerModel);
×
291
              this.swagger.addDefinition(modelName, innerModel);
×
292
            }
293
          }
294
        }
295
      }
296
    }
297
    if (isNotEmptySet(propsToUpdate)) {
248!
298
      properties.putAll(propsToUpdate);
×
299
    }
300
    for (const [key, definition] of modelsToAdd) {
248✔
301
      this.swagger.addDefinition(key, definition);
×
302
      this.addedModels.put(key, definition);
×
303
    }
304
  }
305

306
  public modelFromProperty(object, path) {
307
    if (
×
308
      ((object != null && object instanceof ArrayProperty) ||
×
309
        object === null) &&
310
      (typeof path === 'string' || path === null)
311
    ) {
312
      const description = object.getDescription();
×
313
      let example = null;
×
314
      const obj = object.getExample();
×
315
      if (obj != null) {
×
316
        example = obj.toString();
×
317
      }
318
      const inner = object.getItems();
×
319
      if (inner != null && inner instanceof ObjectProperty) {
×
320
        const model = new ArrayModel();
×
321
        model.setDescription(description);
×
322
        model.setExample(example);
×
323
        model.setItems(object.getItems());
×
324
        return model;
×
325
      }
326
      return null;
×
327
    } else if (
×
328
      ((object != null && object instanceof ObjectProperty) ||
×
329
        object === null) &&
330
      (typeof path === 'string' || path === null)
331
    ) {
332
      return this.modelFromProperty$io_swagger_models_properties_ObjectProperty$java_lang_String(
×
333
        object,
334
        path,
335
      );
336
    } else if (
×
337
      ((object != null && object instanceof MapProperty) || object === null) &&
×
338
      (typeof path === 'string' || path === null)
339
    ) {
340
      return this.modelFromProperty$io_swagger_models_properties_MapProperty$java_lang_String(
×
341
        object,
342
        path,
343
      );
344
    } else {
345
      throw new Error('invalid overload');
×
346
    }
347
  }
348

349
  public modelFromProperty$io_swagger_models_properties_ObjectProperty$java_lang_String(
350
    object,
351
    path,
352
  ) {
353
    const description = object.getDescription();
×
354
    let example = null;
×
355
    const obj = object.getExample();
×
356
    if (obj != null) {
×
357
      example = obj.toString();
×
358
    }
359
    const name = object.getName();
×
360
    const xml = object.getXml();
×
361
    const properties = object.getProperties();
×
362
    const model = new ModelImpl();
×
363
    model.setDescription(description);
×
364
    model.setExample(example);
×
365
    model.setName(name);
×
366
    model.setXml(xml);
×
367
    if (properties != null) {
×
368
      this.flattenProperties(properties, path);
×
369
      model.setProperties(properties);
×
370
    }
371
    return model;
×
372
  }
373

374
  public modelFromProperty$io_swagger_models_properties_MapProperty$java_lang_String(
375
    object,
376
    path,
377
  ) {
378
    const description = object.getDescription();
×
379
    let example = null;
×
380
    const obj = object.getExample();
×
381
    if (obj != null) {
×
382
      example = obj.toString();
×
383
    }
384
    const model = new ArrayModel();
×
385
    model.setDescription(description);
×
386
    model.setExample(example);
×
387
    model.setItems(object.getAdditionalProperties());
×
388
    return model;
×
389
  }
390

391
  public isSkipMatches() {
392
    return this.skipMatches;
×
393
  }
394

395
  public setSkipMatches(skipMatches) {
396
    this.skipMatches = skipMatches;
×
397
  }
398
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc