forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-generated-swagger-descriptions.sh
executable file
·76 lines (66 loc) · 2.63 KB
/
update-generated-swagger-descriptions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# This script generates methods to allow our API objects to describe themsleves for the Swagger tool
# by reading the current version of the Godoc for the objects. This script can either generate new
# documentation or verify that the documentation currently in the repository remains valid.
#
# This script accepts the following parameters as environment variables:
# - VERIFY: run the script to verify current documentation
# - DRY_RUN: print which files would be generated and exit
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
# read in envar options
verify="${VERIFY:-}"
dryrun="${DRY_RUN:-}"
tmpdir="$( mktemp -d )"
mkdir -p "${tmpdir}"
os::util::ensure::built_binary_exists 'genswaggerdoc'
source_files="$( find_files | grep -E '/v1/types.go' )"
if [[ -n "${dryrun}" ]]; then
echo "The following files would be read by $0:"
for file in ${source_files}; do
echo "${file}"
done
exit 0
fi
failed='false'
for file in ${source_files}; do
swagger_file="$( dirname "${file}" )/swagger_doc.go"
if ! genswaggerdoc --input="${file}" --verify > "${tmpdir}/verify.txt" 2>&1; then
echo "[ERROR] Errors in \"${file}\" must be addressed before Swagger documentation can be generated:"
cat "${tmpdir}/verify.txt"
failed='true'
else
tmp_output_file="${tmpdir}/${swagger_file}"
mkdir -p "$( dirname "${tmp_output_file}" )"
package="$( dirname "${file}" )";
echo "package ${package##*/}" > "${tmp_output_file}"
echo "
// This file contains methods that can be used by the go-restful package to generate Swagger
// documentation for the object types found in 'types.go' This file is automatically generated
// by hack/update-generated-swagger-descriptions.sh and should be run after a full build of OpenShift.
// ==== DO NOT EDIT THIS FILE MANUALLY ====
" >> "${tmp_output_file}"
genswaggerdoc --input="${file}" --output="${tmp_output_file}"
gofmt -s -w "${tmp_output_file}"
if [[ -n "${verify}" ]]; then
if ! diff --new-file --unified=3 --text "${tmp_output_file}" "${swagger_file}"; then
echo "[ERROR] Generated Swagger documentation at \"${swagger_file}\" is out of date."
failed='true'
else
os::log::info "Verified that generated Swagger documentation at \"${swagger_file}\" is up to date."
fi
else
mv "${tmp_output_file}" "${swagger_file}"
os::log::info "Generated Swagger documentation written for \"${file}\" to \"${swagger_file}\""
fi
fi
done
verb="generation"
if [[ -n "${verify}" ]]; then
verb="verification"
fi
if [[ "${failed}" = "true" ]]; then
echo "[FAILURE] Swagger API object self-documentation ${verb} failed"
exit 1
fi
echo "[SUCCESS] Swagger API object self-documentation ${verb} succeeded"