From 5c4abd107a4e50b9f2d29f98275a5b5b86c5f50f Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Thu, 3 Nov 2016 10:15:27 -0700 Subject: [PATCH] Add swagger.yaml validation - yamllint to ensure it is a valid YAML file - go-swagger validate to ensure it is a valid swagger file Signed-off-by: Ben Firshman --- Dockerfile | 9 +++++++++ hack/validate/.swagger-yamllint | 4 ++++ hack/validate/default | 1 + hack/validate/swagger | 13 +++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 hack/validate/.swagger-yamllint create mode 100755 hack/validate/swagger diff --git a/Dockerfile b/Dockerfile index 5b6bbc318d..1417a23b93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -194,6 +194,15 @@ RUN git clone https://github.com/docker/docker-py.git /docker-py \ && git checkout -q $DOCKER_PY_COMMIT \ && pip install -r test-requirements.txt +# Install yamllint for validating swagger.yaml +RUN pip install yamllint==1.5.0 + +# Install go-swagger for validating swagger.yaml +ENV GO_SWAGGER_COMMIT c28258affb0b6251755d92489ef685af8d4ff3eb +RUN git clone https://github.com/go-swagger/go-swagger.git /go/src/github.com/go-swagger/go-swagger \ + && (cd /go/src/github.com/go-swagger/go-swagger && git checkout -q $GO_SWAGGER_COMMIT) \ + && go install -v github.com/go-swagger/go-swagger/cmd/swagger + # Set user.email so crosbymichael's in-container merge commits go smoothly RUN git config --global user.email 'docker-dummy@example.com' diff --git a/hack/validate/.swagger-yamllint b/hack/validate/.swagger-yamllint new file mode 100644 index 0000000000..2f00cb666c --- /dev/null +++ b/hack/validate/.swagger-yamllint @@ -0,0 +1,4 @@ +extends: default +rules: + document-start: disable + line-length: disable diff --git a/hack/validate/default b/hack/validate/default index 3ae5f5c03b..198f73066f 100755 --- a/hack/validate/default +++ b/hack/validate/default @@ -9,6 +9,7 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . $SCRIPTDIR/gofmt . $SCRIPTDIR/lint . $SCRIPTDIR/pkg-imports +. $SCRIPTDIR/swagger . $SCRIPTDIR/test-imports . $SCRIPTDIR/toml . $SCRIPTDIR/vet diff --git a/hack/validate/swagger b/hack/validate/swagger new file mode 100755 index 0000000000..e754fb8cb9 --- /dev/null +++ b/hack/validate/swagger @@ -0,0 +1,13 @@ +#!/bin/bash +set -e +export 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 [ ${#files[@]} -gt 0 ]; then + yamllint -c ${SCRIPTDIR}/.swagger-yamllint api/swagger.yaml + swagger validate api/swagger.yaml +fi