Skip to content

Commit 8a21545

Browse files
committed
Use order defined in AutoAPI spec when serializing custom values
1 parent dfc64ee commit 8a21545

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@highmobility/auto-api-javascript",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Auto API for JavaScript - the parsing library for the Auto API vehicle data model",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/values/CustomValue.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ export class CustomValue extends Value<CustomValueItems, CustomValueSetter> impl
121121
}
122122

123123
public valueOf() {
124-
const { value } = this;
124+
const { value, definition } = this;
125+
const { items } = definition as CustomValueDefinition;
126+
125127
if (value) {
126-
return Object.entries(value).reduce<Record<string, unknown>>(
127-
(all, [name, value]) => ({
128+
return items.reduce<Record<string, unknown>>(
129+
(all, { name }) => ({
128130
...all,
129-
[name]: value.valueOf(),
131+
[name]: value[name].valueOf(),
130132
}),
131133
{},
132134
);
@@ -135,11 +137,14 @@ export class CustomValue extends Value<CustomValueItems, CustomValueSetter> impl
135137
}
136138

137139
protected assignValueToItems(values: Record<string, unknown>) {
140+
const { items } = this.definition as CustomValueDefinition;
138141
const valueMap: CustomValueItems = (this._value = (this._value as CustomValueItems) || {});
139142

140-
for (const [key, value] of Object.entries(values)) {
141-
(valueMap[key] =
142-
valueMap[key] || this.createValueInstance(this.getItemTypeDefinition(key))).setValue(value);
143+
for (const { name } of items) {
144+
(valueMap[name] =
145+
valueMap[name] || this.createValueInstance(this.getItemTypeDefinition(name))).setValue(
146+
values[name],
147+
);
143148
}
144149
}
145150

0 commit comments

Comments
 (0)