api: remove unused DefaultVersion, MinSupportedAPIVersion consts

These consts are no longer used, and separate consts were added in both
the client and daemon packages;

- client: 41da5700a4
- daemon: a632b8495b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-07-31 23:09:13 +02:00
committed by Austin Vazquez
parent 8e946ee3d0
commit e46a991dc5
22 changed files with 77 additions and 13623 deletions

View File

@@ -1,16 +0,0 @@
package api
// Common constants for daemon and client.
const (
// DefaultVersion of the current REST API.
DefaultVersion = "1.52"
// MinSupportedAPIVersion is the minimum API version that can be supported
// by the API server, specified as "major.minor". Note that the daemon
// may be configured with a different minimum API version, as returned
// in [github.com/moby/moby/api/types.Version.MinAPIVersion].
//
// API requests for API versions lower than the configured version produce
// an error.
MinSupportedAPIVersion = "1.24"
)

View File

@@ -91,15 +91,14 @@ import (
// [Go stdlib]: https://github.com/golang/go/blob/6244b1946bc2101b01955468f1be502dbadd6807/src/net/http/transport.go#L558-L569
const DummyHost = "api.moby.localhost"
// DefaultAPIVersion is the highest REST API version supported by the client.
// MaxAPIVersion is the highest REST API version supported by the client.
// If API-version negotiation is enabled (see [WithAPIVersionNegotiation],
// [Client.NegotiateAPIVersion]), the client may downgrade its API version.
// Similarly, the [WithVersion] and [WithVersionFromEnv] allow overriding
// the version.
//
// This version may be lower than the [api.DefaultVersion], which is the default
// (and highest supported) version of the api library module used.
const DefaultAPIVersion = "1.52"
// This version may be lower than the version of the api library module used.
const MaxAPIVersion = "1.52"
// fallbackAPIVersion is the version to fallback to if API-version negotiation
// fails. This version is the highest version of the API before API-version
@@ -179,7 +178,7 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
c := &Client{
clientConfig: clientConfig{
host: DefaultDockerHost,
version: DefaultAPIVersion,
version: MaxAPIVersion,
client: client,
proto: hostURL.Scheme,
addr: hostURL.Host,
@@ -363,7 +362,7 @@ func (cli *Client) negotiateAPIVersionPing(pingResponse types.Ping) {
// if the client is not initialized with a version, start with the latest supported version
if cli.version == "" {
cli.version = DefaultAPIVersion
cli.version = MaxAPIVersion
}
// if server version is lower than the client version, downgrade

View File

@@ -29,7 +29,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
{
doc: "default api version",
envs: map[string]string{},
expectedVersion: DefaultAPIVersion,
expectedVersion: MaxAPIVersion,
},
{
doc: "invalid cert path",
@@ -43,7 +43,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
envs: map[string]string{
"DOCKER_CERT_PATH": "testdata/",
},
expectedVersion: DefaultAPIVersion,
expectedVersion: MaxAPIVersion,
},
{
doc: "default api version with cert path and tls verify",
@@ -51,7 +51,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
"DOCKER_CERT_PATH": "testdata/",
"DOCKER_TLS_VERIFY": "1",
},
expectedVersion: DefaultAPIVersion,
expectedVersion: MaxAPIVersion,
},
{
doc: "default api version with cert path and host",
@@ -59,7 +59,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
"DOCKER_CERT_PATH": "testdata/",
"DOCKER_HOST": "https://notaunixsocket",
},
expectedVersion: DefaultAPIVersion,
expectedVersion: MaxAPIVersion,
},
{
doc: "invalid docker host",
@@ -73,7 +73,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
envs: map[string]string{
"DOCKER_HOST": "invalid://url",
},
expectedVersion: DefaultAPIVersion,
expectedVersion: MaxAPIVersion,
},
{
doc: "override api version",
@@ -116,17 +116,17 @@ func TestGetAPIPath(t *testing.T) {
}{
{
path: "/containers/json",
expected: "/v" + DefaultAPIVersion + "/containers/json",
expected: "/v" + MaxAPIVersion + "/containers/json",
},
{
path: "/containers/json",
query: url.Values{},
expected: "/v" + DefaultAPIVersion + "/containers/json",
expected: "/v" + MaxAPIVersion + "/containers/json",
},
{
path: "/containers/json",
query: url.Values{"s": []string{"c"}},
expected: "/v" + DefaultAPIVersion + "/containers/json?s=c",
expected: "/v" + MaxAPIVersion + "/containers/json?s=c",
},
{
version: "1.22",
@@ -234,7 +234,7 @@ func TestNewClientWithOpsFromEnvSetsDefaultVersion(t *testing.T) {
client, err := NewClientWithOpts(FromEnv)
assert.NilError(t, err)
assert.Check(t, is.Equal(client.ClientVersion(), DefaultAPIVersion))
assert.Check(t, is.Equal(client.ClientVersion(), MaxAPIVersion))
const expected = "1.22"
t.Setenv("DOCKER_API_VERSION", expected)
@@ -374,8 +374,8 @@ func TestNegotiateAPIVersionAutomatic(t *testing.T) {
)
assert.NilError(t, err)
// Client defaults to use DefaultAPIVersion before version-negotiation.
expected := DefaultAPIVersion
// Client defaults to use MaxAPIVersion before version-negotiation.
expected := MaxAPIVersion
assert.Check(t, is.Equal(client.ClientVersion(), expected))
// First request should trigger negotiation
@@ -422,7 +422,7 @@ func TestCustomAPIVersion(t *testing.T) {
}{
{
version: "",
expected: DefaultAPIVersion,
expected: MaxAPIVersion,
},
{
version: "1.0",
@@ -434,7 +434,7 @@ func TestCustomAPIVersion(t *testing.T) {
},
{
version: "v",
expected: DefaultAPIVersion,
expected: MaxAPIVersion,
},
{
version: "v1.0",

View File

@@ -237,7 +237,7 @@ func WithTLSClientConfigFromEnv() Opt {
//
// WithVersion does not validate if the client supports the given version,
// and callers should verify if the version is in the correct format and
// lower than the maximum supported version as defined by [DefaultAPIVersion].
// lower than the maximum supported version as defined by [MaxAPIVersion].
func WithVersion(version string) Opt {
return func(c *clientConfig) error {
if v := strings.TrimPrefix(version, "v"); v != "" {
@@ -255,7 +255,7 @@ func WithVersion(version string) Opt {
//
// WithVersion does not validate if the client supports the given version,
// and callers should verify if the version is in the correct format and
// lower than the maximum supported version as defined by [DefaultAPIVersion].
// lower than the maximum supported version as defined by [MaxAPIVersion].
func WithVersionFromEnv() Opt {
return func(c *clientConfig) error {
return WithVersion(os.Getenv(EnvOverrideAPIVersion))(c)

View File

@@ -49,7 +49,7 @@ func TestOptionWithVersionFromEnv(t *testing.T) {
c, err := NewClientWithOpts(WithVersionFromEnv())
assert.NilError(t, err)
assert.Check(t, c.client != nil)
assert.Check(t, is.Equal(c.version, DefaultAPIVersion))
assert.Check(t, is.Equal(c.version, MaxAPIVersion))
assert.Check(t, is.Equal(c.manualOverride, false))
t.Setenv("DOCKER_API_VERSION", "2.9999")

View File

@@ -742,7 +742,7 @@ func initMiddlewares(_ context.Context, s *apiserver.Server, cfg *config.Config,
exp := middleware.NewExperimentalMiddleware(cfg.Experimental)
s.UseMiddleware(exp)
vm, err := middleware.NewVersionMiddleware(dockerversion.Version, config.DefaultAPIVersion, cfg.MinAPIVersion)
vm, err := middleware.NewVersionMiddleware(dockerversion.Version, config.MaxAPIVersion, cfg.MinAPIVersion)
if err != nil {
return nil, err
}

View File

@@ -13,7 +13,6 @@ import (
"dario.cat/mergo"
"github.com/containerd/log"
"github.com/moby/moby/api"
"github.com/moby/moby/api/types/versions"
dopts "github.com/moby/moby/v2/daemon/internal/opts"
"github.com/moby/moby/v2/daemon/pkg/opts"
@@ -56,16 +55,15 @@ const (
DefaultContainersNamespace = "moby"
// DefaultPluginNamespace is the name of the default containerd namespace used for plugins.
DefaultPluginNamespace = "plugins.moby"
// DefaultAPIVersion is the highest REST API version supported by the daemon.
// MaxAPIVersion is the highest REST API version supported by the daemon.
//
// This version may be lower than the [api.DefaultVersion], which is the default
// (and highest supported) version of the api library module used.
DefaultAPIVersion = "1.52"
// defaultMinAPIVersion is the minimum API version supported by the API.
// This version may be lower than the version of the api library module used.
MaxAPIVersion = "1.52"
// MinAPIVersion is the minimum API version supported by the API.
// This version can be overridden through the "DOCKER_MIN_API_VERSION"
// environment variable. It currently defaults to the minimum API version
// supported by the API server.
defaultMinAPIVersion = api.MinSupportedAPIVersion
// implemented in the API module.
MinAPIVersion = "1.24"
// SeccompProfileDefault is the built-in default seccomp profile.
SeccompProfileDefault = "builtin"
// SeccompProfileUnconfined is a special profile name for seccomp to use an
@@ -342,7 +340,7 @@ func New() (*Config, error) {
ContainerdPluginNamespace: DefaultPluginNamespace,
Features: make(map[string]bool),
DefaultRuntime: StockRuntimeName,
MinAPIVersion: defaultMinAPIVersion,
MinAPIVersion: MinAPIVersion,
},
}
@@ -676,11 +674,11 @@ func ValidateMinAPIVersion(ver string) error {
if strings.EqualFold(ver[0:1], "v") {
return errors.New(`API version must be provided without "v" prefix`)
}
if versions.LessThan(ver, defaultMinAPIVersion) {
return errors.Errorf(`minimum supported API version is %s: %s`, defaultMinAPIVersion, ver)
if versions.LessThan(ver, MinAPIVersion) {
return errors.Errorf(`minimum supported API version is %s: %s`, MinAPIVersion, ver)
}
if versions.GreaterThan(ver, DefaultAPIVersion) {
return errors.Errorf(`maximum supported API version is %s: %s`, DefaultAPIVersion, ver)
if versions.GreaterThan(ver, MaxAPIVersion) {
return errors.Errorf(`maximum supported API version is %s: %s`, MaxAPIVersion, ver)
}
return nil
}

View File

@@ -633,7 +633,7 @@ func TestValidateMinAPIVersion(t *testing.T) {
},
{
doc: "current version",
input: DefaultAPIVersion,
input: MaxAPIVersion,
},
}

View File

@@ -114,7 +114,7 @@ func (daemon *Daemon) SystemVersion(ctx context.Context) (types.Version, error)
Version: dockerversion.Version,
Details: map[string]string{
"GitCommit": dockerversion.GitCommit,
"ApiVersion": config.DefaultAPIVersion,
"ApiVersion": config.MaxAPIVersion,
"MinAPIVersion": cfg.MinAPIVersion,
"GoVersion": runtime.Version(),
"Os": runtime.GOOS,
@@ -129,7 +129,7 @@ func (daemon *Daemon) SystemVersion(ctx context.Context) (types.Version, error)
// Populate deprecated fields for older clients
Version: dockerversion.Version,
GitCommit: dockerversion.GitCommit,
APIVersion: config.DefaultAPIVersion,
APIVersion: config.MaxAPIVersion,
MinAPIVersion: cfg.MinAPIVersion,
GoVersion: runtime.Version(),
Os: runtime.GOOS,

View File

@@ -6,7 +6,6 @@ import (
"net/http"
"runtime"
"github.com/moby/moby/api"
"github.com/moby/moby/api/types/versions"
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/daemon/server/httputils"
@@ -19,7 +18,7 @@ type VersionMiddleware struct {
// defaultAPIVersion is the default API version provided by the API server,
// specified as "major.minor". It is usually configured to the latest API
// version [config.DefaultAPIVersion] supported by the daemon.
// version [config.MaxAPIVersion] supported by the daemon.
//
// API requests for API versions greater than this version are rejected by
// the server and produce a [versionUnsupportedError].
@@ -35,11 +34,11 @@ type VersionMiddleware struct {
// NewVersionMiddleware creates a VersionMiddleware with the given versions.
func NewVersionMiddleware(serverVersion, defaultAPIVersion, minAPIVersion string) (*VersionMiddleware, error) {
if versions.LessThan(defaultAPIVersion, api.MinSupportedAPIVersion) || versions.GreaterThan(defaultAPIVersion, config.DefaultAPIVersion) {
return nil, fmt.Errorf("invalid default API version (%s): must be between %s and %s", defaultAPIVersion, api.MinSupportedAPIVersion, config.DefaultAPIVersion)
if versions.LessThan(defaultAPIVersion, config.MinAPIVersion) || versions.GreaterThan(defaultAPIVersion, config.MaxAPIVersion) {
return nil, fmt.Errorf("invalid default API version (%s): must be between %s and %s", defaultAPIVersion, config.MinAPIVersion, config.MaxAPIVersion)
}
if versions.LessThan(minAPIVersion, api.MinSupportedAPIVersion) || versions.GreaterThan(minAPIVersion, config.DefaultAPIVersion) {
return nil, fmt.Errorf("invalid minimum API version (%s): must be between %s and %s", minAPIVersion, api.MinSupportedAPIVersion, config.DefaultAPIVersion)
if versions.LessThan(minAPIVersion, config.MinAPIVersion) || versions.GreaterThan(minAPIVersion, config.MaxAPIVersion) {
return nil, fmt.Errorf("invalid minimum API version (%s): must be between %s and %s", minAPIVersion, config.MinAPIVersion, config.MaxAPIVersion)
}
if versions.GreaterThan(minAPIVersion, defaultAPIVersion) {
return nil, fmt.Errorf("invalid API version: the minimum API version (%s) is higher than the default version (%s)", minAPIVersion, defaultAPIVersion)

View File

@@ -8,7 +8,6 @@ import (
"runtime"
"testing"
"github.com/moby/moby/api"
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/daemon/server/httputils"
"gotest.tools/v3/assert"
@@ -21,38 +20,38 @@ func TestNewVersionMiddlewareValidation(t *testing.T) {
}{
{
doc: "defaults",
defaultVersion: config.DefaultAPIVersion,
minVersion: api.MinSupportedAPIVersion,
defaultVersion: config.MaxAPIVersion,
minVersion: config.MinAPIVersion,
},
{
doc: "invalid default lower than min",
defaultVersion: api.MinSupportedAPIVersion,
minVersion: config.DefaultAPIVersion,
expectedErr: fmt.Sprintf("invalid API version: the minimum API version (%s) is higher than the default version (%s)", config.DefaultAPIVersion, api.MinSupportedAPIVersion),
defaultVersion: config.MinAPIVersion,
minVersion: config.MaxAPIVersion,
expectedErr: fmt.Sprintf("invalid API version: the minimum API version (%s) is higher than the default version (%s)", config.MaxAPIVersion, config.MinAPIVersion),
},
{
doc: "invalid default too low",
defaultVersion: "0.1",
minVersion: api.MinSupportedAPIVersion,
expectedErr: fmt.Sprintf("invalid default API version (0.1): must be between %s and %s", api.MinSupportedAPIVersion, config.DefaultAPIVersion),
minVersion: config.MinAPIVersion,
expectedErr: fmt.Sprintf("invalid default API version (0.1): must be between %s and %s", config.MinAPIVersion, config.MaxAPIVersion),
},
{
doc: "invalid default too high",
defaultVersion: "9999.9999",
minVersion: config.DefaultAPIVersion,
expectedErr: fmt.Sprintf("invalid default API version (9999.9999): must be between %s and %s", api.MinSupportedAPIVersion, config.DefaultAPIVersion),
minVersion: config.MaxAPIVersion,
expectedErr: fmt.Sprintf("invalid default API version (9999.9999): must be between %s and %s", config.MinAPIVersion, config.MaxAPIVersion),
},
{
doc: "invalid minimum too low",
defaultVersion: api.MinSupportedAPIVersion,
defaultVersion: config.MinAPIVersion,
minVersion: "0.1",
expectedErr: fmt.Sprintf("invalid minimum API version (0.1): must be between %s and %s", api.MinSupportedAPIVersion, config.DefaultAPIVersion),
expectedErr: fmt.Sprintf("invalid minimum API version (0.1): must be between %s and %s", config.MinAPIVersion, config.MaxAPIVersion),
},
{
doc: "invalid minimum too high",
defaultVersion: config.DefaultAPIVersion,
defaultVersion: config.MaxAPIVersion,
minVersion: "9999.9999",
expectedErr: fmt.Sprintf("invalid minimum API version (9999.9999): must be between %s and %s", api.MinSupportedAPIVersion, config.DefaultAPIVersion),
expectedErr: fmt.Sprintf("invalid minimum API version (9999.9999): must be between %s and %s", config.MinAPIVersion, config.MaxAPIVersion),
},
}
@@ -76,7 +75,7 @@ func TestVersionMiddlewareVersion(t *testing.T) {
return nil
}
m, err := NewVersionMiddleware("1.2.3", config.DefaultAPIVersion, api.MinSupportedAPIVersion)
m, err := NewVersionMiddleware("1.2.3", config.MaxAPIVersion, config.MinAPIVersion)
assert.NilError(t, err)
h := m.WrapHandler(handler)
@@ -90,19 +89,19 @@ func TestVersionMiddlewareVersion(t *testing.T) {
errString string
}{
{
expectedVersion: config.DefaultAPIVersion,
expectedVersion: config.MaxAPIVersion,
},
{
reqVersion: api.MinSupportedAPIVersion,
expectedVersion: api.MinSupportedAPIVersion,
reqVersion: config.MinAPIVersion,
expectedVersion: config.MinAPIVersion,
},
{
reqVersion: "0.1",
errString: fmt.Sprintf("client version 0.1 is too old. Minimum supported API version is %s, please upgrade your client to a newer version", api.MinSupportedAPIVersion),
errString: fmt.Sprintf("client version 0.1 is too old. Minimum supported API version is %s, please upgrade your client to a newer version", config.MinAPIVersion),
},
{
reqVersion: "9999.9999",
errString: fmt.Sprintf("client version 9999.9999 is too new. Maximum supported API version is %s", config.DefaultAPIVersion),
errString: fmt.Sprintf("client version 9999.9999 is too new. Maximum supported API version is %s", config.MaxAPIVersion),
},
}
@@ -126,7 +125,7 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
return nil
}
m, err := NewVersionMiddleware("1.2.3", config.DefaultAPIVersion, api.MinSupportedAPIVersion)
m, err := NewVersionMiddleware("1.2.3", config.MaxAPIVersion, config.MinAPIVersion)
assert.NilError(t, err)
h := m.WrapHandler(handler)
@@ -141,6 +140,6 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
hdr := resp.Result().Header
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/1.2.3"))
assert.Check(t, is.Contains(hdr.Get("Server"), runtime.GOOS))
assert.Check(t, is.Equal(hdr.Get("Api-Version"), config.DefaultAPIVersion))
assert.Check(t, is.Equal(hdr.Get("Api-Version"), config.MaxAPIVersion))
assert.Check(t, is.Equal(hdr.Get("Ostype"), runtime.GOOS))
}

View File

@@ -63,7 +63,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc, operation string) ht
if statusCode >= http.StatusInternalServerError {
log.G(ctx).Errorf("Handler for %s %s returned error: %v", r.Method, r.URL.Path, err)
}
// While we no longer support API versions older 1.24 [api.MinSupportedAPIVersion],
// While we no longer support API versions older than 1.24 [config.DefaultMinAPIVersion],
// a client may try to connect using an older version and expect a plain-text error
// instead of a JSON error. This would result in an "API version too old" error
// formatted in JSON being printed as-is.

View File

@@ -7,7 +7,6 @@ import (
"strings"
"testing"
"github.com/moby/moby/api"
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/daemon/server/httputils"
"github.com/moby/moby/v2/daemon/server/middleware"
@@ -16,7 +15,7 @@ import (
func TestMiddlewares(t *testing.T) {
srv := &Server{}
m, err := middleware.NewVersionMiddleware("0.1omega2", config.DefaultAPIVersion, api.MinSupportedAPIVersion)
m, err := middleware.NewVersionMiddleware("0.1omega2", config.MaxAPIVersion, config.MinAPIVersion)
if err != nil {
t.Fatal(err)
}

View File

@@ -8,12 +8,12 @@ import (
"testing"
cerrdefs "github.com/containerd/errdefs"
"github.com/moby/moby/api"
containertypes "github.com/moby/moby/api/types/container"
mounttypes "github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/versions"
"github.com/moby/moby/client"
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/daemon/volume"
"github.com/moby/moby/v2/integration/internal/container"
"github.com/moby/moby/v2/pkg/parsers/kernel"
@@ -497,8 +497,8 @@ func TestContainerBindMountReadOnlyDefault(t *testing.T) {
{clientVersion: "1.43", expectedOut: nonRecursive, name: "older than 1.44 should be non-recursive by default"},
// TODO: Remove when MinSupportedAPIVersion >= 1.44
{clientVersion: api.MinSupportedAPIVersion, expectedOut: nonRecursive, name: "minimum API should be non-recursive by default"},
// TODO: Remove when DefaultMinAPIVersion >= 1.44
{clientVersion: config.MinAPIVersion, expectedOut: nonRecursive, name: "minimum API should be non-recursive by default"},
} {
t.Run(tc.name, func(t *testing.T) {
apiClient := testEnv.APIClient()

View File

@@ -8,12 +8,12 @@ import (
"time"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/moby/moby/api"
containertypes "github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/versions"
"github.com/moby/moby/client"
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/integration/internal/container"
iimage "github.com/moby/moby/v2/integration/internal/image"
"github.com/moby/moby/v2/internal/testutils/specialimage"
@@ -262,8 +262,8 @@ func TestAPIImagesListManifests(t *testing.T) {
container.WithPlatform(&containerPlatform))
t.Run("unsupported before 1.47", func(t *testing.T) {
// TODO: Remove when MinSupportedAPIVersion >= 1.47
c := d.NewClientT(t, client.WithVersion(api.MinSupportedAPIVersion))
// TODO: Remove when MinAPIVersion >= 1.47
c := d.NewClientT(t, client.WithVersion(config.MinAPIVersion))
images, err := c.ImageList(ctx, client.ImageListOptions{Manifests: true})
assert.NilError(t, err)

View File

@@ -1,49 +0,0 @@
# Engine API
[![PkgGoDev](https://pkg.go.dev/badge/github.com/moby/moby/api)](https://pkg.go.dev/github.com/moby/moby/api)
![GitHub License](https://img.shields.io/github/license/moby/moby)
[![Go Report Card](https://goreportcard.com/badge/github.com/moby/moby/api)](https://goreportcard.com/report/github.com/moby/moby/api)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/moby/moby/badge)](https://scorecard.dev/viewer/?uri=github.com/moby/moby)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/10989/badge)](https://www.bestpractices.dev/projects/10989)
The Engine API is an HTTP API used by the command-line client to communicate with the daemon. It can also be used by third-party software to control the daemon.
It consists of various components in this repository:
- `api/swagger.yaml` A Swagger definition of the API.
- `api/types/` Types shared by both the client and server, representing various objects, options, responses, etc. Most are written manually, but some are automatically generated from the Swagger definition. See [#27919](https://github.com/moby/moby/issues/27919) for progress on this.
- `client/` The Go client used by the command-line client. It can also be used by third-party Go programs.
- `daemon/` The daemon, which serves the API.
## Swagger definition
The API is defined by the [Swagger](http://swagger.io/specification/) definition in `api/swagger.yaml`. This definition can be used to:
1. Automatically generate documentation.
2. Automatically generate the Go server and client. (A work-in-progress.)
3. Provide a machine readable version of the API for introspecting what it can do, automatically generating clients for other languages, etc.
## Updating the API documentation
The API documentation is generated entirely from `api/swagger.yaml`. If you make updates to the API, edit this file to represent the change in the documentation.
Documentation for each API version can be found in the [docs directory](docs/README.md), which also provides a [CHANGELOG.md](docs/CHANGELOG.md).
The file is split into two main sections:
- `definitions`, which defines re-usable objects used in requests and responses
- `paths`, which defines the API endpoints (and some inline objects which don't need to be reusable)
To make an edit, first look for the endpoint you want to edit under `paths`, then make the required edits. Endpoints may reference reusable objects with `$ref`, which can be found in the `definitions` section.
There is hopefully enough example material in the file for you to copy a similar pattern from elsewhere in the file (e.g. adding new fields or endpoints), but for the full reference, see the [Swagger specification](https://github.com/moby/moby/issues/27919).
`swagger.yaml` is validated by `hack/validate/swagger` to ensure it is a valid Swagger definition. This is useful when making edits to ensure you are doing the right thing.
## Viewing the API documentation
When you make edits to `swagger.yaml`, you may want to check the generated API documentation to ensure it renders correctly.
Run `make swagger-docs` and a preview will be running at `http://localhost:9000`. Some of the styling may be incorrect, but you'll be able to ensure that it is generating the correct documentation.
The production documentation is generated by vendoring `swagger.yaml` into [docker/docs](https://github.com/docker/docs).

View File

@@ -1,16 +0,0 @@
package api
// Common constants for daemon and client.
const (
// DefaultVersion of the current REST API.
DefaultVersion = "1.52"
// MinSupportedAPIVersion is the minimum API version that can be supported
// by the API server, specified as "major.minor". Note that the daemon
// may be configured with a different minimum API version, as returned
// in [github.com/moby/moby/api/types.Version.MinAPIVersion].
//
// API requests for API versions lower than the configured version produce
// an error.
MinSupportedAPIVersion = "1.24"
)

View File

@@ -1,12 +0,0 @@
layout:
models:
- name: definition
source: asset:model
target: "{{ joinFilePath .Target .ModelPackage }}"
file_name: "{{ (snakize (pascalize .Name)) }}.go"
operations:
- name: handler
source: asset:serverOperation
target: "{{ joinFilePath .Target .APIPackage .Package }}"
file_name: "{{ (snakize (pascalize .Name)) }}.go"

File diff suppressed because it is too large Load Diff

View File

@@ -91,15 +91,14 @@ import (
// [Go stdlib]: https://github.com/golang/go/blob/6244b1946bc2101b01955468f1be502dbadd6807/src/net/http/transport.go#L558-L569
const DummyHost = "api.moby.localhost"
// DefaultAPIVersion is the highest REST API version supported by the client.
// MaxAPIVersion is the highest REST API version supported by the client.
// If API-version negotiation is enabled (see [WithAPIVersionNegotiation],
// [Client.NegotiateAPIVersion]), the client may downgrade its API version.
// Similarly, the [WithVersion] and [WithVersionFromEnv] allow overriding
// the version.
//
// This version may be lower than the [api.DefaultVersion], which is the default
// (and highest supported) version of the api library module used.
const DefaultAPIVersion = "1.52"
// This version may be lower than the version of the api library module used.
const MaxAPIVersion = "1.52"
// fallbackAPIVersion is the version to fallback to if API-version negotiation
// fails. This version is the highest version of the API before API-version
@@ -179,7 +178,7 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
c := &Client{
clientConfig: clientConfig{
host: DefaultDockerHost,
version: DefaultAPIVersion,
version: MaxAPIVersion,
client: client,
proto: hostURL.Scheme,
addr: hostURL.Host,
@@ -363,7 +362,7 @@ func (cli *Client) negotiateAPIVersionPing(pingResponse types.Ping) {
// if the client is not initialized with a version, start with the latest supported version
if cli.version == "" {
cli.version = DefaultAPIVersion
cli.version = MaxAPIVersion
}
// if server version is lower than the client version, downgrade

View File

@@ -237,7 +237,7 @@ func WithTLSClientConfigFromEnv() Opt {
//
// WithVersion does not validate if the client supports the given version,
// and callers should verify if the version is in the correct format and
// lower than the maximum supported version as defined by [DefaultAPIVersion].
// lower than the maximum supported version as defined by [MaxAPIVersion].
func WithVersion(version string) Opt {
return func(c *clientConfig) error {
if v := strings.TrimPrefix(version, "v"); v != "" {
@@ -255,7 +255,7 @@ func WithVersion(version string) Opt {
//
// WithVersion does not validate if the client supports the given version,
// and callers should verify if the version is in the correct format and
// lower than the maximum supported version as defined by [DefaultAPIVersion].
// lower than the maximum supported version as defined by [MaxAPIVersion].
func WithVersionFromEnv() Opt {
return func(c *clientConfig) error {
return WithVersion(os.Getenv(EnvOverrideAPIVersion))(c)

1
vendor/modules.txt vendored
View File

@@ -940,7 +940,6 @@ github.com/moby/ipvs
github.com/moby/locker
# github.com/moby/moby/api v1.52.0-alpha.1 => ./api
## explicit; go 1.23.0
github.com/moby/moby/api
github.com/moby/moby/api/pkg/authconfig
github.com/moby/moby/api/pkg/progress
github.com/moby/moby/api/pkg/stdcopy