Skip to content

Commit

Permalink
Use order defined in AutoAPI spec when serializing custom values
Browse files Browse the repository at this point in the history
  • Loading branch information
unematiii committed Apr 18, 2022
1 parent dfc64ee commit 8a21545
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@highmobility/auto-api-javascript",
"version": "1.1.1",
"version": "1.1.2",
"description": "Auto API for JavaScript - the parsing library for the Auto API vehicle data model",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
19 changes: 12 additions & 7 deletions src/values/CustomValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ export class CustomValue extends Value<CustomValueItems, CustomValueSetter> impl
}

public valueOf() {
const { value } = this;
const { value, definition } = this;
const { items } = definition as CustomValueDefinition;

if (value) {
return Object.entries(value).reduce<Record<string, unknown>>(
(all, [name, value]) => ({
return items.reduce<Record<string, unknown>>(
(all, { name }) => ({
...all,
[name]: value.valueOf(),
[name]: value[name].valueOf(),
}),
{},
);
Expand All @@ -135,11 +137,14 @@ export class CustomValue extends Value<CustomValueItems, CustomValueSetter> impl
}

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

for (const [key, value] of Object.entries(values)) {
(valueMap[key] =
valueMap[key] || this.createValueInstance(this.getItemTypeDefinition(key))).setValue(value);
for (const { name } of items) {
(valueMap[name] =
valueMap[name] || this.createValueInstance(this.getItemTypeDefinition(name))).setValue(
values[name],
);
}
}

Expand Down

0 comments on commit 8a21545

Please sign in to comment.