cncf-tags / container-device-interface

Apache License 2.0
206 stars 38 forks source link

Ensure that YAML marshalling maintains field ordering #235

Open elezar opened 2 hours ago

elezar commented 2 hours ago

When outputing the following spec as YAML:

cdi.Spec{
    Version: "v0.3.0",
    Kind:    "example.com/class",
    ContainerEdits: cdi.ContainerEdits{
    DeviceNodes: []*cdi.DeviceNode{
        {
            Path: "/dev/foo",
        },
    },
}

We get the following output:

---
cdiVersion: v0.3.0
containerEdits:
  deviceNodes:
  - path: /dev/foo
devices: null
kind: example.com/class

Which does not maintain ordering of the fields as defines in the spec.

The JSON output is as follows:

{"cdiVersion":"v0.3.0","kind":"example.com/class","devices":null,"containerEdits":{"deviceNodes":[{"path":"/dev/foo"}]}}
elezar commented 2 hours ago

@klihub @bart0sh what are youre thoughts here? I'm willing to concede that this isn't too important, but reading generated specs becomes cumbersome expecially since the kind information is at the end of the file.