Pragmatism in the real world

Running Spectral lint in Gitlab CI

In my Makefile, I check for OpenAPI spec issues with this command:

docker run --rm -it -v $(PWD):/tmp stoplight/spectral lint \
  --ruleset /tmp/spec/.spectral.yaml /tmp/spec/openapi.yaml

When running in GitLab CI, we set the image to stoplight/spectral:latest, and override the entry point so that we can run spectral directly:

openapi-lint:
  stage: test
  image:
    name: stoplight/spectral:latest
    entrypoint: [""]
  script:
    - spectral lint --ruleset spec/.spectral.yaml spec/openapi.yaml

Note that GitLab’s CI running automatically sets the current working directly to the directly where our source code is mounted, so we don’t need to go hunting for it which is useful.

Screenshot of Gitlab CI output when running spectral successfully.

Maybe I should automate creation of the HTML docs from the spec and uploading it somewhere useful next.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *