Default behaviour of JSON marshalling for nil slices? #42632
Labels
area/api
kind/enhancement
Enhancements are not bugs or new features but can improve usability or performance.
tl;dr: Should
nil
Golang slices always be returned as JSON[]
on the api?Description
The current swagger api docs declare most slices and objects as non-nullable arrays. Some properties are marshalled to JSON
null
when the Golang slice ro struct isnil
. See #42607 for an example.I'm also working on a modified
hackcopy at https://github.com/docker-client/docker-engine/blob/main/engine-api-model/docker-engine-api-v1.41.yaml, and I would like to apply my custom fixes upstream. I'm uncertain in which direction a fix should be made, considering the following options:x-nullable: true
where the runtime returns JSONnull
.nil
slices to return an empty JSON array[]
.Here's the current list of properties where I found a mismatch between the 1.41 api swagger docs and the actual api. Please consider this list as work-in-progress:
ImageSummary.RepoTags
(array, should be JSON[]
on the api)ImageSummary.RepoDigests
(array, should be JSON[]
on the api)ImageSummary.Labels
(object, should be declaredx-nullable:true
)Volume.Labels
(object, should be declaredx-nullable:true
)Volume.Options
(object, should be declaredx-nullable:true
)VolumeListResponse.Warnings
(array, should be JSON[]
on the api)Additional information you deem important (e.g. issue happens only occasionally):
Articles like https://medium.com/swlh/arrays-and-json-in-go-98540f2fa74e provide some ideas, yet, each with a tradeoff.
Output of
docker version
:Output of
docker info
:The text was updated successfully, but these errors were encountered: