api/t/network: generate Inspect, Summary structs

Replace the hand-rolled Network, Summary and Inspect struct types in
api/types/network with types generated from the Swagger definition.

Disable the generation of all unwanted marshalers and unmarshalers.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider
2025-08-26 17:56:30 -04:00
parent c208f90796
commit ea1c2530da
13 changed files with 509 additions and 240 deletions

View File

@@ -2439,10 +2439,13 @@ definitions:
Name of the network.
type: "string"
example: "my_network"
x-omitempty: false
Id:
description: |
ID that uniquely identifies a network on a single machine.
type: "string"
x-go-name: "ID"
x-omitempty: false
example: "7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99"
Created:
description: |
@@ -2450,36 +2453,53 @@ definitions:
[RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
type: "string"
format: "dateTime"
x-omitempty: false
x-go-type:
type: Time
import:
package: time
hints:
nullable: false
example: "2016-10-19T04:33:30.360899459Z"
Scope:
description: |
The level at which the network exists (e.g. `swarm` for cluster-wide
or `local` for machine level)
type: "string"
x-omitempty: false
example: "local"
Driver:
description: |
The name of the driver used to create the network (e.g. `bridge`,
`overlay`).
type: "string"
x-omitempty: false
example: "overlay"
EnableIPv4:
description: |
Whether the network was created with IPv4 enabled.
type: "boolean"
x-omitempty: false
example: true
EnableIPv6:
description: |
Whether the network was created with IPv6 enabled.
type: "boolean"
x-omitempty: false
example: false
IPAM:
description: |
The network's IP Address Management.
$ref: "#/definitions/IPAM"
x-nullable: false
x-omitempty: false
Internal:
description: |
Whether the network is created to only allow internal networking
connectivity.
type: "boolean"
x-nullable: false
x-omitempty: false
default: false
example: false
Attachable:
@@ -2487,16 +2507,22 @@ definitions:
Whether a global / swarm scope network is manually attachable by regular
containers from workers in swarm mode.
type: "boolean"
x-nullable: false
x-omitempty: false
default: false
example: false
Ingress:
description: |
Whether the network is providing the routing-mesh for the swarm cluster.
type: "boolean"
x-nullable: false
x-omitempty: false
default: false
example: false
ConfigFrom:
$ref: "#/definitions/ConfigReference"
x-nullable: false
x-omitempty: false
ConfigOnly:
description: |
Whether the network is a config-only network. Config-only networks are
@@ -2504,24 +2530,14 @@ definitions:
networks. Config-only networks cannot be used directly to run containers
or services.
type: "boolean"
x-omitempty: false
x-nullable: false
default: false
Containers:
description: |
Contains endpoints attached to the network.
type: "object"
additionalProperties:
$ref: "#/definitions/NetworkContainer"
example:
19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c:
Name: "test"
EndpointID: "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a"
MacAddress: "02:42:ac:13:00:02"
IPv4Address: "172.19.0.2/16"
IPv6Address: ""
Options:
description: |
Network-specific options uses when creating the network.
type: "object"
x-omitempty: false
additionalProperties:
type: "string"
example:
@@ -2532,8 +2548,10 @@ definitions:
com.docker.network.bridge.name: "docker0"
com.docker.network.driver.mtu: "1500"
Labels:
description: "User-defined key/value metadata."
description: |
Metadata specific to the network being created.
type: "object"
x-omitempty: false
additionalProperties:
type: "string"
example:
@@ -2544,12 +2562,53 @@ definitions:
List of peer nodes for an overlay network. This field is only present
for overlay networks, and omitted for other network types.
type: "array"
x-omitempty: true
items:
$ref: "#/definitions/PeerInfo"
x-nullable: true
# TODO: Add Services (only present when "verbose" is set).
NetworkSummary:
description: "Network list response item"
x-go-name: Summary
type: "object"
allOf:
- $ref: "#/definitions/Network"
NetworkInspect:
description: 'The body of the "get network" http response message.'
x-go-name: Inspect
type: "object"
allOf:
- $ref: "#/definitions/Network"
properties:
Containers:
description: |
Contains endpoints attached to the network.
type: "object"
x-omitempty: false
additionalProperties:
$ref: "#/definitions/EndpointResource"
example:
19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c:
Name: "test"
EndpointID: "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a"
MacAddress: "02:42:ac:13:00:02"
IPv4Address: "172.19.0.2/16"
IPv6Address: ""
Services:
description: |
List of services using the network. This field is only present for
swarm scope networks, and omitted for local scope networks.
type: "object"
x-omitempty: true
additionalProperties:
x-go-type:
type: ServiceInfo
hints:
nullable: false
ConfigReference:
x-nullable: false
x-omitempty: false
description: |
The config-only network source to provide the configuration for
this network.
@@ -2565,6 +2624,8 @@ definitions:
IPAM:
type: "object"
x-nullable: false
x-omitempty: false
properties:
Driver:
description: "Name of the IPAM driver to use."
@@ -2606,7 +2667,7 @@ definitions:
additionalProperties:
type: "string"
NetworkContainer:
EndpointResource:
type: "object"
properties:
Name:
@@ -2629,6 +2690,7 @@ definitions:
description: |
PeerInfo represents one peer of an overlay network.
type: "object"
x-nullable: false
properties:
Name:
description:
@@ -11036,7 +11098,7 @@ paths:
schema:
type: "array"
items:
$ref: "#/definitions/Network"
$ref: "#/definitions/NetworkSummary"
examples:
application/json:
- Name: "bridge"
@@ -11127,7 +11189,7 @@ paths:
200:
description: "No error"
schema:
$ref: "#/definitions/Network"
$ref: "#/definitions/NetworkInspect"
404:
description: "Network not found"
schema:

View File

@@ -74,7 +74,7 @@
{{- end }}
{{ template "mapOrSliceGetter" . }}
{{- end }}
{{ template "schemaSerializer" . }}
{{/* {{ template "schemaSerializer" . }} */}}
{{- end }}
{{- if and .IncludeValidator (not .IsSuperAlias) (not .IsEmbedded) }}{{/* aliased types type A = B do not redefine methods */}}
{{- if and (not (or .IsInterface .IsStream)) (or .Required .HasValidations .HasBaseType) }}
@@ -111,7 +111,7 @@ func ({{.ReceiverName}} {{ if or .IsTuple .IsComplexObject .IsAdditionalProperti
{{- end }}
{{- end }}
{{- if .WantsMarshalBinary }}
{{ template "marshalBinarySerializer" . }}
{{/* {{ template "marshalBinarySerializer" . }} */}}
{{- end }}
{{- end }}
{{- define "mapOrSliceGetter" }}{{/* signature for AdditionalProperties and AdditionalItems getter funcs */}}

View File

@@ -1 +0,0 @@
{{ define "marshalBinarySerializer" }}{{ end }}

View File

@@ -3,7 +3,8 @@
// {{ template "docstring" . }}
{{- template "propertyValidationDocString" .}}
{{- end}}
{{ pascalize .Name}} {{ template "schemaType" . }} {{ .PrintTags }}
{{- /* Work around bug where "IPv4" and "IPv6" specifically get mangled to "IPV4" and "IPV6", respectively. */}}
{{ pascalize .Name | replace "IPV4" "IPv4" | replace "IPV6" "IPv6" }} {{ template "schemaType" . }} {{ .PrintTags }}
{{ end }}
{{- define "tuplefield" }}

View File

@@ -0,0 +1,23 @@
// Code generated by go-swagger; DO NOT EDIT.
package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// Inspect The body of the "get network" http response message.
//
// swagger:model Inspect
type Inspect struct {
Network
// Contains endpoints attached to the network.
//
// Example: {"19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c":{"EndpointID":"628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a","IPv4Address":"172.19.0.2/16","IPv6Address":"","MacAddress":"02:42:ac:13:00:02","Name":"test"}}
Containers map[string]EndpointResource `json:"Containers"`
// List of services using the network. This field is only present for
// swarm scope networks, and omitted for local scope networks.
//
Services map[string]ServiceInfo `json:"Services,omitempty"`
}

View File

@@ -1,125 +1,100 @@
// Code generated by go-swagger; DO NOT EDIT.
package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"time"
timeext "time"
)
const (
// NetworkDefault is a platform-independent alias to choose the platform-specific default network stack.
NetworkDefault = "default"
// NetworkHost is the name of the predefined network used when the NetworkMode host is selected (only available on Linux)
NetworkHost = "host"
// NetworkNone is the name of the predefined network used when the NetworkMode none is selected (available on both Linux and Windows)
NetworkNone = "none"
// NetworkBridge is the name of the default network on Linux
NetworkBridge = "bridge"
// NetworkNat is the name of the default network on Windows
NetworkNat = "nat"
)
// CreateRequest is the request message sent to the server for network create call.
type CreateRequest struct {
Name string // Name is the requested name of the network.
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`)
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level).
EnableIPv4 *bool `json:",omitempty"` // EnableIPv4 represents whether to enable IPv4.
EnableIPv6 *bool `json:",omitempty"` // EnableIPv6 represents whether to enable IPv6.
IPAM *IPAM // IPAM is the network's IP Address Management.
Internal bool // Internal represents if the network is used internal only.
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
ConfigFrom *ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate *bool `json:",omitempty"`
}
// Network network
//
// swagger:model Network
type Network struct {
Name string // Name is the name of the network
ID string `json:"Id"` // ID uniquely identifies a network on a single machine
Created time.Time // Created is the time the network created
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
EnableIPv4 bool // EnableIPv4 represents whether IPv4 is enabled
EnableIPv6 bool // EnableIPv6 represents whether IPv6 is enabled
IPAM IPAM // IPAM is the network's IP Address Management
Internal bool // Internal represents if the network is used internal only
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigFrom ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
Options map[string]string // Options holds the network specific options to use for when creating the network
Labels map[string]string // Labels holds metadata specific to the network being created
Peers []PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
}
// Inspect is the body of the "get network" http response message.
type Inspect struct {
Network
Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
Services map[string]ServiceInfo `json:",omitempty"`
}
// Name of the network.
//
// Example: my_network
Name string `json:"Name"`
// Summary is used as response when listing networks.
type Summary struct {
Network
}
// ID that uniquely identifies a network on a single machine.
//
// Example: 7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99
ID string `json:"Id"`
// Address represents an IP address
type Address struct {
Addr string
PrefixLen int
}
// Date and time at which the network was created in
// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
//
// Example: 2016-10-19T04:33:30.360899459Z
Created timeext.Time `json:"Created"`
// PeerInfo represents one peer of an overlay network
type PeerInfo struct {
Name string
IP string
}
// The level at which the network exists (e.g. `swarm` for cluster-wide
// or `local` for machine level)
//
// Example: local
Scope string `json:"Scope"`
// Task carries the information about one backend task
type Task struct {
Name string
EndpointID string
EndpointIP string
Info map[string]string
}
// The name of the driver used to create the network (e.g. `bridge`,
// `overlay`).
//
// Example: overlay
Driver string `json:"Driver"`
// ServiceInfo represents service parameters with the list of service's tasks
type ServiceInfo struct {
VIP string
Ports []string
LocalLBIndex int
Tasks []Task
}
// Whether the network was created with IPv4 enabled.
//
// Example: true
EnableIPv4 bool `json:"EnableIPv4"`
// EndpointResource contains network resources allocated and used for a
// container in a network.
type EndpointResource struct {
Name string
EndpointID string
MacAddress string
IPv4Address string
IPv6Address string
}
// Whether the network was created with IPv6 enabled.
//
// Example: false
EnableIPv6 bool `json:"EnableIPv6"`
// NetworkingConfig represents the container's networking configuration for each of its interfaces
// Carries the networking configs specified in the `docker run` and `docker network connect` commands
type NetworkingConfig struct {
EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each connecting network
}
// The network's IP Address Management.
//
IPAM IPAM `json:"IPAM"`
// ConfigReference specifies the source which provides a network's configuration
type ConfigReference struct {
Network string
}
// Whether the network is created to only allow internal networking
// connectivity.
//
// Example: false
Internal bool `json:"Internal"`
// PruneReport contains the response for Engine API:
// POST "/networks/prune"
type PruneReport struct {
NetworksDeleted []string
// Whether a global / swarm scope network is manually attachable by regular
// containers from workers in swarm mode.
//
// Example: false
Attachable bool `json:"Attachable"`
// Whether the network is providing the routing-mesh for the swarm cluster.
//
// Example: false
Ingress bool `json:"Ingress"`
// config from
ConfigFrom ConfigReference `json:"ConfigFrom"`
// Whether the network is a config-only network. Config-only networks are
// placeholder networks for network configurations to be used by other
// networks. Config-only networks cannot be used directly to run containers
// or services.
//
ConfigOnly bool `json:"ConfigOnly"`
// Network-specific options uses when creating the network.
//
// Example: {"com.docker.network.bridge.default_bridge":"true","com.docker.network.bridge.enable_icc":"true","com.docker.network.bridge.enable_ip_masquerade":"true","com.docker.network.bridge.host_binding_ipv4":"0.0.0.0","com.docker.network.bridge.name":"docker0","com.docker.network.driver.mtu":"1500"}
Options map[string]string `json:"Options"`
// Metadata specific to the network being created.
//
// Example: {"com.example.some-label":"some-value","com.example.some-other-label":"some-other-value"}
Labels map[string]string `json:"Labels"`
// List of peer nodes for an overlay network. This field is only present
// for overlay networks, and omitted for other network types.
//
Peers []PeerInfo `json:"Peers,omitempty"`
}

View File

@@ -0,0 +1,90 @@
package network
const (
// NetworkDefault is a platform-independent alias to choose the platform-specific default network stack.
NetworkDefault = "default"
// NetworkHost is the name of the predefined network used when the NetworkMode host is selected (only available on Linux)
NetworkHost = "host"
// NetworkNone is the name of the predefined network used when the NetworkMode none is selected (available on both Linux and Windows)
NetworkNone = "none"
// NetworkBridge is the name of the default network on Linux
NetworkBridge = "bridge"
// NetworkNat is the name of the default network on Windows
NetworkNat = "nat"
)
// CreateRequest is the request message sent to the server for network create call.
type CreateRequest struct {
Name string // Name is the requested name of the network.
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`)
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level).
EnableIPv4 *bool `json:",omitempty"` // EnableIPv4 represents whether to enable IPv4.
EnableIPv6 *bool `json:",omitempty"` // EnableIPv6 represents whether to enable IPv6.
IPAM *IPAM // IPAM is the network's IP Address Management.
Internal bool // Internal represents if the network is used internal only.
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
ConfigFrom *ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate *bool `json:",omitempty"`
}
// Address represents an IP address
type Address struct {
Addr string
PrefixLen int
}
// PeerInfo represents one peer of an overlay network
type PeerInfo struct {
Name string
IP string
}
// Task carries the information about one backend task
type Task struct {
Name string
EndpointID string
EndpointIP string
Info map[string]string
}
// ServiceInfo represents service parameters with the list of service's tasks
type ServiceInfo struct {
VIP string
Ports []string
LocalLBIndex int
Tasks []Task
}
// EndpointResource contains network resources allocated and used for a
// container in a network.
type EndpointResource struct {
Name string
EndpointID string
MacAddress string
IPv4Address string
IPv6Address string
}
// NetworkingConfig represents the container's networking configuration for each of its interfaces
// Carries the networking configs specified in the `docker run` and `docker network connect` commands
type NetworkingConfig struct {
EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each connecting network
}
// ConfigReference specifies the source which provides a network's configuration
type ConfigReference struct {
Network string
}
// PruneReport contains the response for Engine API:
// POST "/networks/prune"
type PruneReport struct {
NetworksDeleted []string
}

View File

@@ -0,0 +1,13 @@
// Code generated by go-swagger; DO NOT EDIT.
package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// Summary Network list response item
//
// swagger:model Summary
type Summary struct {
Network
}