Browse code

Merge pull request #28038 from bfirsh/add-validate-swagger

Validation for swagger.yaml

Vincent Demeester authored on 2016/11/08 18:57:01
Showing 5 changed files
... ...
@@ -195,6 +195,15 @@ RUN git clone https://github.com/docker/docker-py.git /docker-py \
195 195
 	&& git checkout -q $DOCKER_PY_COMMIT \
196 196
 	&& pip install -r test-requirements.txt
197 197
 
198
+# Install yamllint for validating swagger.yaml
199
+RUN pip install yamllint==1.5.0
200
+
201
+# Install go-swagger for validating swagger.yaml
202
+ENV GO_SWAGGER_COMMIT c28258affb0b6251755d92489ef685af8d4ff3eb
203
+RUN git clone https://github.com/go-swagger/go-swagger.git /go/src/github.com/go-swagger/go-swagger \
204
+	&& (cd /go/src/github.com/go-swagger/go-swagger && git checkout -q $GO_SWAGGER_COMMIT) \
205
+	&& go install -v github.com/go-swagger/go-swagger/cmd/swagger
206
+
198 207
 # Set user.email so crosbymichael's in-container merge commits go smoothly
199 208
 RUN git config --global user.email 'docker-dummy@example.com'
200 209
 
... ...
@@ -12,6 +12,8 @@ basePath: "/v1.25"
12 12
 info:
13 13
   title: "Docker Remote API"
14 14
   version: "1.25"
15
+  x-logo:
16
+    url: "https://docs.docker.com/images/logo-docker-main.png"
15 17
   description: |
16 18
     The Docker API is an HTTP REST API served by Docker Engine. It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API.
17 19
 
... ...
@@ -234,7 +236,7 @@ definitions:
234 234
       BlkioWeight:
235 235
         description: "Block IO weight (relative weight)."
236 236
         type: "integer"
237
-        minimum: 10
237
+        minimum: 0
238 238
         maximum: 1000
239 239
       BlkioWeightDevice:
240 240
         description: |
... ...
@@ -1692,6 +1694,7 @@ definitions:
1692 1692
         $ref: "#/definitions/SwarmSpec"
1693 1693
   TaskSpec:
1694 1694
     description: "User modifiable task configuration."
1695
+    type: "object"
1695 1696
     properties:
1696 1697
       ContainerSpec:
1697 1698
         type: "object"
... ...
@@ -2277,9 +2280,6 @@ paths:
2277 2277
                 NetworkSettings:
2278 2278
                   Networks:
2279 2279
                     bridge:
2280
-                      IPAMConfig: null
2281
-                      Links: null
2282
-                      Aliases: null
2283 2280
                       NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812"
2284 2281
                       EndpointID: "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f"
2285 2282
                       Gateway: "172.17.0.1"
... ...
@@ -2315,9 +2315,6 @@ paths:
2315 2315
                 NetworkSettings:
2316 2316
                   Networks:
2317 2317
                     bridge:
2318
-                      IPAMConfig: null
2319
-                      Links: null
2320
-                      Aliases: null
2321 2318
                       NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812"
2322 2319
                       EndpointID: "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a"
2323 2320
                       Gateway: "172.17.0.1"
... ...
@@ -2346,9 +2343,6 @@ paths:
2346 2346
                 NetworkSettings:
2347 2347
                   Networks:
2348 2348
                     bridge:
2349
-                      IPAMConfig: null
2350
-                      Links: null
2351
-                      Aliases: null
2352 2349
                       NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812"
2353 2350
                       EndpointID: "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d"
2354 2351
                       Gateway: "172.17.0.1"
... ...
@@ -2377,9 +2371,6 @@ paths:
2377 2377
                 NetworkSettings:
2378 2378
                   Networks:
2379 2379
                     bridge:
2380
-                      IPAMConfig: null
2381
-                      Links: null
2382
-                      Aliases: null
2383 2380
                       NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812"
2384 2381
                       EndpointID: "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9"
2385 2382
                       Gateway: "172.17.0.1"
... ...
@@ -2721,10 +2712,8 @@ paths:
2721 2721
                   - "-c"
2722 2722
                   - "exit 9"
2723 2723
                 Domainname: ""
2724
-                Entrypoint: null
2725 2724
                 Env:
2726 2725
                   - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
2727
-                ExposedPorts: null
2728 2726
                 Hostname: "ba033ac44011"
2729 2727
                 Image: "ubuntu"
2730 2728
                 Labels:
... ...
@@ -2733,7 +2722,6 @@ paths:
2733 2733
                   com.example.version: "1.0"
2734 2734
                 MacAddress: ""
2735 2735
                 NetworkDisabled: false
2736
-                OnBuild: null
2737 2736
                 OpenStdin: false
2738 2737
                 StdinOnce: false
2739 2738
                 Tty: false
... ...
@@ -2744,9 +2732,7 @@ paths:
2744 2744
                 StopSignal: "SIGTERM"
2745 2745
               Created: "2015-01-06T15:47:31.485331387Z"
2746 2746
               Driver: "devicemapper"
2747
-              ExecIDs: null
2748 2747
               HostConfig:
2749
-                Binds: null
2750 2748
                 MaximumIOps: 0
2751 2749
                 MaximumIOBps: 0
2752 2750
                 BlkioWeight: 0
... ...
@@ -2760,8 +2746,6 @@ paths:
2760 2760
                   - {}
2761 2761
                 BlkioDeviceWriteIOps:
2762 2762
                   - {}
2763
-                CapAdd: null
2764
-                CapDrop: null
2765 2763
                 ContainerIDFile: ""
2766 2764
                 CpusetCpus: ""
2767 2765
                 CpusetMems: ""
... ...
@@ -2769,12 +2753,7 @@ paths:
2769 2769
                 CpuShares: 0
2770 2770
                 CpuPeriod: 100000
2771 2771
                 Devices: []
2772
-                Dns: null
2773
-                DnsOptions: null
2774
-                DnsSearch: null
2775
-                ExtraHosts: null
2776 2772
                 IpcMode: ""
2777
-                Links: null
2778 2773
                 LxcConf: []
2779 2774
                 Memory: 0
2780 2775
                 MemorySwap: 0
... ...
@@ -2792,13 +2771,9 @@ paths:
2792 2792
                   MaximumRetryCount: 2
2793 2793
                   Name: "on-failure"
2794 2794
                 LogConfig:
2795
-                  Config: null
2796 2795
                   Type: "json-file"
2797
-                SecurityOpt: null
2798 2796
                 Sysctls:
2799 2797
                   net.ipv4.ip_forward: "1"
2800
-                StorageOpt: null
2801
-                VolumesFrom: null
2802 2798
                 Ulimits:
2803 2799
                   - {}
2804 2800
                 VolumeDriver: ""
... ...
@@ -2816,7 +2791,6 @@ paths:
2816 2816
                 HairpinMode: false
2817 2817
                 LinkLocalIPv6Address: ""
2818 2818
                 LinkLocalIPv6PrefixLen: 0
2819
-                Ports: null
2820 2819
                 SandboxKey: ""
2821 2820
                 SecondaryIPAddresses: null
2822 2821
                 SecondaryIPv6Addresses: null
... ...
@@ -3865,18 +3839,25 @@ paths:
3865 3865
               type: "string"
3866 3866
               description: "TODO"
3867 3867
         400:
3868
-          description: "client error, bad parameter, details in JSON response body, one of: must specify path parameter (path cannot be empty) not a directory (path was asserted to be a directory but exists as a file)"
3868
+          description: "Bad parameter"
3869 3869
           schema:
3870
-            $ref: "#/definitions/ErrorResponse"
3870
+            allOf:
3871
+              - $ref: "#/definitions/ErrorResponse"
3872
+              - type: "object"
3873
+                properties:
3874
+                  message:
3875
+                    description: "The error message. Either \"must specify path parameter\" (path cannot be empty) or \"not a directory\" (path was asserted to be a directory but exists as a file)."
3876
+                    type: "string"
3877
+                    x-nullable: false
3871 3878
         404:
3872
-          description: "client error, resource not found, one of: 1) no such container (container id does not exist) 2) no such file or directory (path resource does not exist)"
3879
+          description: "Container or path does not exist"
3873 3880
           schema:
3874 3881
             $ref: "#/definitions/ErrorResponse"
3875 3882
           examples:
3876 3883
             application/json:
3877 3884
               message: "No such container: c2ada9df5af8"
3878 3885
         500:
3879
-          description: "server error"
3886
+          description: "Server error"
3880 3887
           schema:
3881 3888
             $ref: "#/definitions/ErrorResponse"
3882 3889
       parameters:
... ...
@@ -3902,11 +3883,18 @@ paths:
3902 3902
         200:
3903 3903
           description: "no error"
3904 3904
         400:
3905
-          description: "client error, bad parameter, details in JSON response body, one of: must specify path parameter (path cannot be empty) not a directory (path was asserted to be a directory but exists as a file)"
3905
+          description: "Bad parameter"
3906 3906
           schema:
3907
-            $ref: "#/definitions/ErrorResponse"
3907
+            allOf:
3908
+              - $ref: "#/definitions/ErrorResponse"
3909
+              - type: "object"
3910
+                properties:
3911
+                  message:
3912
+                    description: "The error message. Either \"must specify path parameter\" (path cannot be empty) or \"not a directory\" (path was asserted to be a directory but exists as a file)."
3913
+                    type: "string"
3914
+                    x-nullable: false
3908 3915
         404:
3909
-          description: "client error, resource not found, one of: 1) no such container (container id does not exist) 2) no such file or directory (path resource does not exist)"
3916
+          description: "Container or path does not exist"
3910 3917
           schema:
3911 3918
             $ref: "#/definitions/ErrorResponse"
3912 3919
           examples:
... ...
@@ -3997,25 +3985,33 @@ paths:
3997 3997
               $ref: "#/definitions/ImageSummary"
3998 3998
           examples:
3999 3999
             application/json:
4000
-              - RepoTags:
4000
+              - Id: "sha256:e216a057b1cb1efc11f8a268f37ef62083e70b1b38323ba252e25ac88904a7e8"
4001
+                ParentId: ""
4002
+                RepoTags:
4001 4003
                   - "ubuntu:12.04"
4002 4004
                   - "ubuntu:precise"
4003
-                  - "ubuntu:latest"
4004
-                Id: "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c"
4005
-                Created: 1365714795
4006
-                Size: 131506275
4007
-                VirtualSize: 131506275
4005
+                RepoDigests:
4006
+                  - "ubuntu@sha256:992069aee4016783df6345315302fa59681aae51a8eeb2f889dea59290f21787"
4007
+                Created: 1474925151
4008
+                Size: 103579269
4009
+                VirtualSize: 103579269
4010
+                SharedSize: 0
4008 4011
                 Labels: {}
4009
-              - RepoTags:
4012
+                Containers: 2
4013
+              - Id: "sha256:3e314f95dcace0f5e4fd37b10862fe8398e3c60ed36600bc0ca5fda78b087175"
4014
+                ParentId: ""
4015
+                RepoTags:
4010 4016
                   - "ubuntu:12.10"
4011 4017
                   - "ubuntu:quantal"
4012
-                ParentId: "27cf784147099545"
4013
-                Id: "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc"
4014
-                Created: 1364102658
4015
-                Size: 24653
4016
-                VirtualSize: 180116135
4017
-                Labels:
4018
-                  com.example.version: "v1"
4018
+                RepoDigests:
4019
+                  - "ubuntu@sha256:002fba3e3255af10be97ea26e476692a7ebed0bb074a9ab960b2e7a1526b15d7"
4020
+                  - "ubuntu@sha256:68ea0200f0b90df725d99d823905b04cf844f6039ef60c60bf3e019915017bd3"
4021
+                Created: 1403128455
4022
+                Size: 172064416
4023
+                VirtualSize: 172064416
4024
+                SharedSize: 0
4025
+                Labels: {}
4026
+                Containers: 5
4019 4027
         500:
4020 4028
           description: "server error"
4021 4029
           schema:
... ...
@@ -4241,7 +4237,6 @@ paths:
4241 4241
               ContainerConfig:
4242 4242
                 Tty: false
4243 4243
                 Hostname: "e611e15f9c9d"
4244
-                Volumes: null
4245 4244
                 Domainname: ""
4246 4245
                 AttachStdout: false
4247 4246
                 PublishService: ""
... ...
@@ -4253,7 +4248,6 @@ paths:
4253 4253
                 Image: "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c"
4254 4254
                 User: ""
4255 4255
                 WorkingDir: ""
4256
-                Entrypoint: null
4257 4256
                 MacAddress: ""
4258 4257
                 AttachStderr: false
4259 4258
                 Labels:
... ...
@@ -4262,7 +4256,6 @@ paths:
4262 4262
                   com.example.vendor: "Acme"
4263 4263
                 Env:
4264 4264
                   - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
4265
-                ExposedPorts: null
4266 4265
                 Cmd:
4267 4266
                   - "/bin/sh"
4268 4267
                   - "-c"
... ...
@@ -4274,7 +4267,6 @@ paths:
4274 4274
               Created: "2015-09-10T08:30:53.26995814Z"
4275 4275
               GraphDriver:
4276 4276
                 Name: "aufs"
4277
-                Data: null
4278 4277
               RepoDigests:
4279 4278
                 - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"
4280 4279
               RepoTags:
... ...
@@ -4293,17 +4285,14 @@ paths:
4293 4293
                 AttachStdout: false
4294 4294
                 Tty: false
4295 4295
                 Hostname: "e611e15f9c9d"
4296
-                Volumes: null
4297 4296
                 Cmd:
4298 4297
                   - "/bin/bash"
4299
-                ExposedPorts: null
4300 4298
                 Env:
4301 4299
                   - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
4302 4300
                 Labels:
4303 4301
                   com.example.vendor: "Acme"
4304 4302
                   com.example.version: "1.0"
4305 4303
                   com.example.license: "GPL"
4306
-                Entrypoint: null
4307 4304
                 MacAddress: ""
4308 4305
                 AttachStderr: false
4309 4306
                 WorkingDir: ""
... ...
@@ -4376,7 +4365,7 @@ paths:
4376 4376
               - Id: "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8"
4377 4377
                 Created: 1398108222
4378 4378
                 CreatedBy: "/bin/sh -c #(nop) MAINTAINER Tianon Gravi <admwiggin@gmail.com> - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/"
4379
-                Tags: null
4379
+                Tags: []
4380 4380
                 Size: 0
4381 4381
                 Comment: ""
4382 4382
               - Id: "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
... ...
@@ -4834,7 +4823,6 @@ paths:
4834 4834
               RegistryConfig:
4835 4835
                 IndexConfigs:
4836 4836
                   docker.io:
4837
-                    Mirrors: null
4838 4837
                     Name: "docker.io"
4839 4838
                     Official: true
4840 4839
                     Secure: true
... ...
@@ -5035,6 +5023,7 @@ paths:
5035 5035
               timeNano:
5036 5036
                 description: "Timestamp of event, with nanosecond accuracy"
5037 5037
                 type: "integer"
5038
+                format: "int64"
5038 5039
           examples:
5039 5040
             application/json:
5040 5041
               Type: "container"
... ...
@@ -5046,7 +5035,6 @@ paths:
5046 5046
                   image: "alpine"
5047 5047
                   name: "my-container"
5048 5048
               time: 1461943101
5049
-              timeNano: 1461943101381709551
5050 5049
         500:
5051 5050
           description: "server error"
5052 5051
           schema:
... ...
@@ -5425,6 +5413,7 @@ paths:
5425 5425
                     com.example.some-label: "some-value"
5426 5426
                     com.example.some-other-label: "some-other-value"
5427 5427
                   Scope: "local"
5428
+                  Options: {}
5428 5429
               Warnings: []
5429 5430
         500:
5430 5431
           description: "Server error"
... ...
@@ -6496,7 +6485,8 @@ paths:
6496 6496
           schema:
6497 6497
             allOf:
6498 6498
               - $ref: "#/definitions/ServiceSpec"
6499
-              - example:
6499
+              - type: "object"
6500
+                example:
6500 6501
                   Name: "web"
6501 6502
                   TaskTemplate:
6502 6503
                     ContainerSpec:
... ...
@@ -6621,7 +6611,8 @@ paths:
6621 6621
           schema:
6622 6622
             allOf:
6623 6623
               - $ref: "#/definitions/ServiceSpec"
6624
-              - example:
6624
+              - type: "object"
6625
+                example:
6625 6626
                   Name: "top"
6626 6627
                   TaskTemplate:
6627 6628
                     ContainerSpec:
6628 6629
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+extends: default
1
+rules:
2
+  document-start: disable
3
+  line-length: disable
... ...
@@ -9,6 +9,7 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9 9
 . $SCRIPTDIR/gofmt
10 10
 . $SCRIPTDIR/lint
11 11
 . $SCRIPTDIR/pkg-imports
12
+. $SCRIPTDIR/swagger
12 13
 . $SCRIPTDIR/test-imports
13 14
 . $SCRIPTDIR/toml
14 15
 . $SCRIPTDIR/vet
15 16
new file mode 100755
... ...
@@ -0,0 +1,13 @@
0
+#!/bin/bash
1
+set -e
2
+export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3
+source "${SCRIPTDIR}/.validate"
4
+
5
+IFS=$'\n'
6
+files=( $(validate_diff --diff-filter=ACMR --name-only -- 'api/swagger.yaml' || true) )
7
+unset IFS
8
+
9
+if [ ${#files[@]} -gt 0 ]; then
10
+  yamllint -c ${SCRIPTDIR}/.swagger-yamllint api/swagger.yaml
11
+  swagger validate api/swagger.yaml
12
+fi