Skip to content

specs-go: fix JSON tag for VM hwConfig - #1331

Merged
tianon merged 1 commit into
opencontainers:mainfrom
RaphaelFakhri:fix-vm-hwconfig-json-tag
Nov 7, 2026
Merged

tianon merged 1 commit into
opencontainers:mainfrom
RaphaelFakhri:fix-vm-hwconfig-json-tag

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The spec (config-vm.md) and the JSON schema (schema/config-vm.json) name the VM hardware configuration property hwConfig. The Go struct tag on VM.HwConfig is hwconfig, so marshaling a config with the Go types produces a key that does not match the spec or the schema. Case-sensitive consumers ignore it.

Before:

{"hypervisor":{"path":""},"kernel":{"path":""},"image":{"path":"","format":""},"hwconfig":{"deviceTree":"/path/to/dt.dtb"}}

After, the key is hwConfig.

Changes

  • specs-go/config.go: change the tag to json:"hwConfig,omitempty".

encoding/json matches keys case-insensitively when decoding, so Go users that read existing documents with hwconfig are not affected.

Comment thread specs-go/config_test.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't seem useful.
We do not have tests for other JSON tags.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, dropped the test in 9d63379.

@AkihiroSuda AkihiroSuda added this to the v1.3.1 milestone Nov 5, 2026
The spec (config-vm.md) and the JSON schema (schema/config-vm.json)
name the VM hardware configuration property "hwConfig", but the Go
struct tag used "hwconfig". Marshaling a VM config with the Go types
therefore produced a key that does not match the spec, and is ignored
by case-sensitive parsers.

Decoding with encoding/json is case-insensitive, so existing documents
using "hwconfig" still decode.

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
@RaphaelFakhri
RaphaelFakhri force-pushed the fix-vm-hwconfig-json-tag branch from 54cb697 to 9d63379 Compare November 6, 2026 20:15
@tianon
tianon merged commit 7bb825e into opencontainers:main Nov 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants