api: move scripts to generate and validate swagger to api module

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

revert api/swagger.yaml to undo formatting

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

refactor(api): update Dockerfile and Makefile with newline at the EOF and use current best practices

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

refactor validations and swagger generation flow

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

shfmt

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

refactor generate-swagger-api.sh to use absolute path

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

add validate-api-swagger job for GitHub Actions

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

fix validate-api-swagger ci workflow

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>

update go version and redoc in api module

Signed-off-by: Rafael Camelo <rafaelcamelo31@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Rafael Camelo
2025-10-26 17:20:28 -04:00
committed by Sebastiaan van Stijn
parent 4dc87c55c7
commit 0666108ebf
12 changed files with 193 additions and 86 deletions

View File

@@ -1,125 +0,0 @@
#!/bin/bash
# vim: set noexpandtab:
# -*- indent-tabs-mode: t -*-
set -eu
generate_model() {
local package="$1"
shift
mapfile
swagger generate model --spec=api/swagger.yaml \
--target=api --model-package="$package" \
--config-file=api/swagger-gen.yaml \
--template-dir=api/templates --allow-template-override \
"$@" \
$(printf -- '--name=%s ' "${MAPFILE[@]}")
}
generate_operation() {
mapfile
swagger generate operation --spec=api/swagger.yaml \
--target=api --api-package=types --model-package=types \
--config-file=api/swagger-gen.yaml \
--template-dir=api/templates --allow-template-override \
"$@" \
$(printf -- '--name=%s ' "${MAPFILE[@]}")
}
# /==================================================================\
# | |
# | ATTENTION: |
# | |
# | Sort model package stanzas and model/operation names |
# | *** ALPHABETICALLY *** |
# | to reduce the likelihood of merge conflicts. |
# | |
# \==================================================================/
#region -------- Models --------
generate_model types/build <<- 'EOT'
BuildCacheDiskUsage
EOT
generate_model types/common <<- 'EOT'
ErrorResponse
IDResponse
EOT
generate_model types/container <<- 'EOT'
ChangeType
ContainerCreateResponse
ContainerTopResponse
ContainerUpdateResponse
ContainerWaitExitError
ContainerWaitResponse
ContainersDiskUsage
FilesystemChange
PortSummary
EOT
generate_model types/image <<- 'EOT'
ImageDeleteResponseItem
ImagesDiskUsage
EOT
# ImageSummary
# TODO: Restore when go-swagger is updated
# See https://github.com/moby/moby/pull/47526#discussion_r1551800022
generate_model types/network --keep-spec-order --additional-initialism=IPAM <<- 'EOT'
ConfigReference
EndpointResource
IPAMStatus
Network
NetworkConnectRequest
NetworkCreateResponse
NetworkDisconnectRequest
NetworkInspect
NetworkStatus
NetworkSummary
NetworkTaskInfo
PeerInfo
ServiceInfo
SubnetStatus
EOT
generate_model types/plugin <<- 'EOT'
Plugin
PluginDevice
PluginEnv
PluginMount
EOT
generate_model types/registry <<- 'EOT'
AuthResponse
EOT
generate_model types/storage <<- 'EOT'
DriverData
RootFSStorage
RootFSStorageSnapshot
Storage
EOT
generate_model types/swarm <<- 'EOT'
ServiceCreateResponse
ServiceUpdateResponse
EOT
generate_model types/volume <<- 'EOT'
Volume
VolumeCreateRequest
VolumeListResponse
VolumesDiskUsage
EOT
#endregion
#region -------- Operations --------
generate_operation --skip-responses --skip-parameters <<- 'EOT'
Authenticate
ImageHistory
EOT
#endregion

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
set -e
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"
IFS=$'\n'
files=($(validate_diff --diff-filter=ACMR --name-only -- 'api/swagger.yaml' || true))
unset IFS
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then
yamllint -f parsable -c "${SCRIPTDIR}"/yamllint.yaml api/swagger.yaml
if out=$(swagger validate api/swagger.yaml); then
echo "Congratulations! ${out}"
else
echo "${out}" >&2
false
fi
fi

View File

@@ -1,29 +0,0 @@
#!/usr/bin/env bash
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"
IFS=$'\n'
files=($(validate_diff --diff-filter=ACMR --name-only -- 'api/types/' 'api/swagger.yaml' || true))
unset IFS
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then
"${SCRIPTDIR}"/../generate-swagger-api.sh 2> /dev/null
# Let see if the working directory is clean
diffs="$(git diff -- api/types/)"
if [ "$diffs" ]; then
{
echo 'The result of hack/generate-swagger-api.sh differs'
echo
echo "$diffs"
echo
echo 'Please update api/swagger.yaml with any API changes, then '
echo 'run hack/generate-swagger-api.sh.'
} >&2
false
else
echo 'Congratulations! All API changes are done the right way.'
fi
else
echo 'No api/types/ or api/swagger.yaml changes in diff.'
fi

View File

@@ -1,29 +0,0 @@
#!/usr/bin/env bash
set -e
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"
if [ -n "${TEST_FORCE_VALIDATE:-}" ]; then
files=(docs/api/*.yaml)
else
IFS=$'\n'
files=($(validate_diff --diff-filter=ACMR --name-only -- docs/*.yaml || true))
unset IFS
fi
# validate the yamllint configuration file before anything else
if out=$(yamllint -f parsable -d "{extends: default, rules: {document-start: disable}}" "${SCRIPTDIR}"/yamllint.yaml); then
echo "Congratulations! yamllint config file formatted correctly"
else
echo "${out}" >&2
false
fi
# Then validate GitHub actions workflows, and conditionally lint the swagger
# files in the docs directory, as these are large files and take some time.
if out=$(yamllint -f parsable -c "${SCRIPTDIR}"/yamllint.yaml .github/workflows/*.yml "${files[@]}"); then
echo "Congratulations! YAML files are formatted correctly"
else
echo "${out}" >&2
false
fi

View File

@@ -1,10 +0,0 @@
extends: default
locale: C.UTF-8
rules:
document-start: disable
line-length: disable
# ignore "warning truthy value should be one of [false, true]" on GitHub
# actions workflows, which use "on:" to specify when to run.
truthy:
ignore: |
.github/workflows/