dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.23k stars 381 forks source link

ServiceCreationMode is missing replicated-job and global-job #674

Open dazinator opened 5 months ago

dazinator commented 5 months ago

This api that lets you list swarm services

   var serviceListParams = new ServicesListParameters()
        {
            Filters = new ServiceFilter()
            {
                Mode = new []
                {
                    ServiceCreationMode.Replicated
                }

the Mode filter requires an ServiceCreationMode enum, but that enum is missing a couple of items

   public class ServicesListParameters
    {
        [QueryStringParameter("filters", false, typeof(MapQueryStringConverter))]
        public ServiceFilter Filters { get; set; }
    }
    public class ServiceFilter : Dictionary<string, string[]>
    {
        public string[] Id
        {
            get => this["id"];
            set => this["id"] = value;
        }
        public string[] Label
        {
            get => this["label"];
            set => this["label"] = value;
        }
        public ServiceCreationMode[] Mode
        {
            get => this["mode"]?.ToList().Select(m => (ServiceCreationMode)Enum.Parse(typeof(ServiceCreationMode), m)).ToArray();
            set => this["mode"] = value?.Select(m => m.ToString()).ToArray();
        }
        public string[] Name
        {
            get => this["name"];
            set => this["name"] = value;
        }
    }

    public enum ServiceCreationMode
    {
        Replicated,
        Global
    }
}

Not too bad as it looks like I should be able to workaround it by directly accessing the dictionary, but then if I set "mode" = "replicated-job" in the dictionary, the "Mode" property get accessor will throw an exception with an invalid cast..