Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f06018a

Browse files
committed
Add Spectral Linter
1 parent a710f74 commit f06018a

File tree

7 files changed

+822
-153
lines changed

7 files changed

+822
-153
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor
2+
/node_modules
23

34
/docker-compose.override.yml
45

‎.spectral.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file configures the spectral OpenAPI linter
2+
#
3+
# The default config extends the pre-defined ruleset for OpenAPI 3.
4+
# Adjust this file to define your own custom rules.
5+
#
6+
# See https://meta.stoplight.io/docs/spectral/01baf06bdd05a-create-a-ruleset
7+
8+
extends: ["spectral:oas"]

‎Makefile‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# set user to "root" to run commands as root in docker
22
USER=$$(whoami)
33
# The docker command to execute commands directly in docker
4-
DOCKER=docker-compose exec -T --user="$(USER)" backend-php
4+
DOCKER=docker-compose exec -T -w /app --user="$(USER)" backend-php
55
# The PHP binary to use, you may add arguments to PHP here
66
PHP=php
77
# directories writeable by webserver
@@ -20,9 +20,10 @@ default:
2020
@echo " make stop-docker stop docker environment"
2121
@echo " make cli run bash in docker environment"
2222
@echo " make bash alias for 'make cli'"
23+
@echo " make lint Run OpenAPI linter"
2324

2425

25-
.PHONY: start stop start-docker stop-docker clean test bash cli
26+
.PHONY: start stop start-docker stop-docker clean test bash cli lint lint-php lint-js
2627

2728

2829
## PHP runtime ##
@@ -81,6 +82,19 @@ backend/config/cookie-validation.key:
8182
test -s $@ || php -r 'echo bin2hex(random_bytes(20));' > $@
8283

8384

85+
# Lint API spec
86+
87+
lint: lint-php lint-js
88+
89+
lint-php:
90+
$(DOCKER) ./vendor/bin/php-openapi validate openapi/schema.yaml
91+
92+
lint-js: node_modules/.bin/spectral
93+
docker-compose run -T --no-deps --rm --user="$$(id -u)" -e FORCE_COLOR=1 -w /app nodejs ./node_modules/.bin/spectral lint openapi/schema.yaml -f stylish --ruleset .spectral.yml
94+
95+
node_modules/.bin/spectral: package.json
96+
docker-compose run -T --no-deps --rm --user="$$(id -u)" -e FORCE_COLOR=1 -w /app nodejs npm install
97+
8498
## Docker Runtime Tests ##
8599

86100
test: tests/_data/dump.sql

‎README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ Your API is now available at `http://localhost:8337/`. Try to access an endpoint
150150
...
151151
]
152152

153+
154+
## Linting the OpenAPI specification
155+
156+
You can run a linter to check the validity of your OpenAPI specification file:
157+
158+
make lint-js # run spectral lint
159+
make lint-php # run php-openapi validate
160+
make lint # run both of the above commands
161+
162+
You can find more information on spectral at <https://www.npmjs.com/package/@stoplight/spectral-cli#-documentation-and-community>.
163+
164+
153165
## Application structure <span id="structure"></span>
154166

155167
This application template consists of 3 application tiers:

‎docker-compose.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ services:
5252
mailcatcher:
5353
image: nisenabe/mailcatcher
5454

55+
# javascript container for running JS OpenAPI linter
56+
nodejs:
57+
image: node
58+
command: 'tail -f /dev/null'
59+
volumes:
60+
- ./:/app

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /