4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenAPI 3.0 (swagger) のバリデーションをCircleCIで回す

Posted at

モチベーション

OpenAPIを使ってAPIの定義を書いているが、ファイルが大きくなってくると定義がOpenAPIの仕様から逸脱していないかの確認が大変になってしまう(いちいち editor.swagger.io に貼り付けるのは面倒だし validator-badge はOAS3.0に未対応っぽい)のでCircleCIでやりたい。

結論

openapi3-validator を使う。
有志が開発している validator をdockerで使えるようにwrapしたものだが、今のところvalidation機能については問題なさそう。

CircleCI設定例

.circleci/config.yml
jobs:
  openapi:
    wordking_directory: ~/myapp
    docker:
      - image: circleci/ruby:2.5-node
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
          version: 17.11.0-ce
      - run:
          name: openapi
          command: |
            docker create -v $(pwd):/openapi --name openapi-validator alpine:3.4 /bin/true
            docker cp ./docs/openapi/myapp-api.yaml openapi-validator:/openapi
            docker run -it -w /openapi --rm --volumes-from openapi-validator usabillabv/openapi3-validator myapp-api.yaml

OpenAPIを記述したyamlをマウントしないといけないので、この辺を使っています

通った時
$ docker run -it -w /openapi --rm --volumes-from openapi-validator usabillabv/openapi3-validator myapp-api.yaml
 [PASS] No errors found
落ちた時
$ docker run -it -w /openapi --rm --volumes-from openapi-validator usabillabv/openapi3-validator myapp-api.yaml
   :
   :
Error #11 in [security]:
    {'http': []} is not of type 'array'
    {'http': []}

 [FAIL] 11 errors found

べんり。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?