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

electrode-io / electrode-native / 7453

01 Aug 2025 08:28PM UTC coverage: 56.454% (-3.6%) from 60.024%
7453

push

Azure Pipelines

web-flow
Merge pull request #1915 from r0h0gg6/container-android-publishing-fix

Declare variants for publishing for AGP 8

3549 of 7723 branches covered (45.95%)

Branch coverage included in aggregate %.

9388 of 15193 relevant lines covered (61.79%)

524.96 hits per line

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

83.92
/ern-api-gen/src/examples/ExampleGenerator.ts
1
import XmlExampleGenerator from './XmlExampleGenerator';
2✔
2
import {
2✔
3
  ArrayProperty,
4
  BooleanProperty,
5
  DateProperty,
6
  DateTimeProperty,
7
  DecimalProperty,
8
  DoubleProperty,
9
  FileProperty,
10
  FloatProperty,
11
  IntegerProperty,
12
  LongProperty,
13
  MapProperty,
14
  ObjectProperty,
15
  RefProperty,
16
  StringProperty,
17
  UUIDProperty,
18
} from '../models/properties';
19
import Json from '../java/Json';
2✔
20
import { asMap, newHashMap, newHashSet } from '../java/javaUtil';
2✔
21

22
export default class ExampleGenerator {
2✔
23
  public examples;
24

25
  constructor(examples) {
26
    this.examples = examples;
382✔
27
  }
28

29
  public generate(examples, mediaTypes, property) {
30
    const output: any[] = [];
382✔
31
    const processedModels = newHashSet();
382✔
32
    if (examples == null) {
382✔
33
      if (mediaTypes == null) {
362!
34
        mediaTypes = ['application/json'];
×
35
      }
36
      for (const mediaType of mediaTypes) {
362✔
37
        const kv = newHashMap(['contentType', mediaType]);
561✔
38
        if (property != null && mediaType.startsWith('application/json')) {
561✔
39
          const rexample = this.resolvePropertyToExample(
356✔
40
            mediaType,
41
            property,
42
            processedModels,
43
          );
44
          const example = JSON.stringify(rexample, null, 2);
356✔
45
          if (example != null) {
356!
46
            kv.put('example', example);
356✔
47
            output.push(kv);
356✔
48
          }
49
        } else if (
205!
50
          property != null &&
410✔
51
          mediaType.startsWith('application/xml')
52
        ) {
53
          const example = new XmlExampleGenerator(this.examples).toXml(
205✔
54
            property,
55
          );
56
          if (example != null) {
205!
57
            kv.put('example', example);
205✔
58
            output.push(kv);
205✔
59
          }
60
        }
61
      }
62
    } else {
63
      for (const [contentType, example] of asMap(examples)) {
20✔
64
        output.push(
20✔
65
          newHashMap(
66
            ['contentType', contentType],
67
            ['example', Json.pretty(example)],
68
          ),
69
        );
70
      }
71
    }
72
    if (output.length === 0) {
382✔
73
      output.push(newHashMap(['output', 'none']));
6✔
74
    }
75
    return JSON.stringify(output);
382✔
76
  }
77

78
  public resolvePropertyToExample(mediaType, property, processedModels) {
79
    if (property.getExample() != null) {
2,260✔
80
      return property.getExample();
61✔
81
    } else if (property instanceof BooleanProperty) {
2,199✔
82
      return 'true';
105✔
83
    } else if (property instanceof ArrayProperty) {
2,094✔
84
      const innerType = property.getItems();
220✔
85
      if (innerType != null) {
220!
86
        return [
220✔
87
          this.resolvePropertyToExample(mediaType, innerType, processedModels),
88
        ];
89
      }
90
    } else if (property instanceof DateProperty) {
1,874!
91
      return '2000-01-23T04:56:07.000+00:00';
×
92
    } else if (property instanceof DateTimeProperty) {
1,874✔
93
      return '2000-01-23T04:56:07.000+00:00';
54✔
94
    } else if (property instanceof DecimalProperty) {
1,820✔
95
      return Number(1.3579).toPrecision(5);
30✔
96
    } else if (property instanceof DoubleProperty) {
1,790✔
97
      return Number(3.149).toPrecision(3);
30✔
98
    } else if (property instanceof FileProperty) {
1,760!
99
      return '';
×
100
    } else if (property instanceof FloatProperty) {
1,760!
101
      return Number(1.23).toPrecision(2);
×
102
    } else if (property instanceof IntegerProperty) {
1,760!
103
      return Number(123).toPrecision(1);
×
104
    } else if (property instanceof LongProperty) {
1,760✔
105
      return Number(123456789).toPrecision(9);
348✔
106
    } else if (property instanceof MapProperty) {
1,412✔
107
      const mp = newHashMap();
27✔
108
      if ((property as any).getName() != null) {
27!
109
        mp.put(
×
110
          (property as any).getName(),
111
          this.resolvePropertyToExample(
112
            mediaType,
113
            property.getAdditionalProperties(),
114
            processedModels,
115
          ),
116
        );
117
      } else {
118
        mp.put(
27✔
119
          'key',
120
          this.resolvePropertyToExample(
121
            mediaType,
122
            property.getAdditionalProperties(),
123
            processedModels,
124
          ),
125
        );
126
      }
127
      return mp;
27✔
128
    } else if (property instanceof ObjectProperty) {
1,385!
129
      return '{}';
×
130
    } else if (property instanceof RefProperty) {
1,385✔
131
      const simpleName = property.getSimpleRef();
388✔
132
      const model = this.examples.get(simpleName);
388✔
133
      if (model != null) {
388!
134
        return this.resolveModelToExample(
388✔
135
          simpleName,
136
          mediaType,
137
          model,
138
          processedModels,
139
        );
140
      }
141
    } else if (property instanceof UUIDProperty) {
997!
142
      return '046b6c7f-0b8a-43b9-b35d-6489e6daee91';
×
143
    } else if (property instanceof StringProperty) {
997✔
144
      return 'aeiou';
852✔
145
    }
146
    return '';
145✔
147
  }
148

149
  public resolveModelToExample(name, mediaType, model, processedModels) {
150
    if (processedModels.contains(name)) {
388✔
151
      return '';
4✔
152
    }
153
    if (model != null) {
384!
154
      processedModels.add(name);
384✔
155
      const values = newHashMap();
384✔
156
      if (model.getProperties() != null) {
384✔
157
        for (const [propertyName, property] of model.getProperties()) {
363✔
158
          values.put(
1,657✔
159
            propertyName,
160
            this.resolvePropertyToExample(mediaType, property, processedModels),
161
          );
162
        }
163
      }
164
      return values;
384✔
165
    }
166
    return '';
×
167
  }
168
}
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