Skip to content

Commit

Permalink
Merge pull request #697 from italia/rules-next
Browse files Browse the repository at this point in the history
Enhanced Rule Management
  • Loading branch information
mfortini authored Jun 14, 2024
2 parents a09cc2e + 064d78f commit a9f7636
Show file tree
Hide file tree
Showing 93 changed files with 209 additions and 3,799 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-node@v2
with:
node-version: '16'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-node@v2
with:
node-version: '16'
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "rules-modi"]
path = rules-modi
url = https://github.com/italia/api-oas-checker-rules.git
branch = main
37 changes: 21 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
#

RULE_FILES := spectral.yml spectral-full.yml spectral-security.yml spectral-generic.yml
RULE_FILES := spectral.yml spectral-full.yml spectral-security.yml spectral-generic.yml spectral-modi.yml
RULE_DOCS := $(RULE_FILES:.yml=.doc.html)

all: clean install rules build test-ui
Expand All @@ -12,31 +12,36 @@ all: clean install rules build test-ui
clean:
rm -f $(RULE_DOCS)
rm -f $(RULE_FILES)
rm -rf functions

# Install node dependencies
install: yarn.lock
rm -rf node_modules
yarn install --frozen-lockfile


# Generate spectral ruleset with documentation
rules: clean $(RULE_FILES)
spectral.yml: ./rules/
cat ./rules/rules-template.yml.template > $@
./rules/merge-yaml rules/*.yml >> $@

rulesets-dir:
@mkdir -p functions
@mkdir -p rules-modi/rulesets
@mkdir -p rules-modi/rulesets/functions

spectral.yml: ./rules-modi/rules/ rulesets-dir
make -C rules-modi $@ && mv rules-modi/rulesets/$@ .
node ruleset_doc_generator.mjs --file $@ --title 'Italian API Guidelines'
spectral-generic.yml: ./rules/ spectral.yml
./rules/merge-yaml spectral.yml rules/skip-italian.yml.template > $@
spectral-generic.yml: ./rules-modi/rules/ spectral.yml rulesets-dir
make -C rules-modi $@ && mv rules-modi/rulesets/$@ .
node ruleset_doc_generator.mjs --file $@ --title 'Best Practices Only'
spectral-security.yml: ./rules/ ./security/
cat ./rules/rules-template.yml.template > $@
./rules/merge-yaml security/*.yml >> $@
mkdir -p ./functions
cp ./security/functions/* ./functions/
spectral-security.yml: ./rules-modi/rules/ ./rules-modi/security/ rulesets-dir
make -C rules-modi $@ && mv rules-modi/rulesets/$@ . && mv rules-modi/rulesets/functions/* functions/
node ruleset_doc_generator.mjs --file $@ --title 'Extra Security Checks'
spectral-full.yml: spectral.yml spectral-security.yml
./rules/merge-yaml spectral.yml spectral-security.yml > $@
spectral-full.yml: spectral.yml spectral-security.yml rulesets-dir
make -C rules-modi $@ && mv rules-modi/rulesets/$@ .
node ruleset_doc_generator.mjs --file $@ --title 'Italian API Guidelines + Extra Security Checks'
spectral-modi.yml: rulesets-dir
make -C rules-modi $@ && mv rules-modi/rulesets/$@ .
node ruleset_doc_generator.mjs --file $@ --title 'ModI Guidelines'

# Build js bundle
build: install rules
Expand All @@ -49,8 +54,8 @@ test-ui: install

# TODO: this doesn't work on MacOS!
test: install
bash test-ruleset.sh rules/ all
bash test-ruleset.sh security/ all
bash test-ruleset.sh rules-modi/rules/ all
bash test-ruleset.sh rules-modi/security/ all

# regression test with existing files
ittest: test rules
Expand Down
122 changes: 10 additions & 112 deletions ittest/fitko.snapshot

Large diffs are not rendered by default.

432 changes: 136 additions & 296 deletions ittest/ingv.snapshot

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions ittest/ittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ test(){
exit 1
fi

spectral lint -r "${RULESET}" -D -F warn "${openapi}" | \
diff - "${snapshot}.snapshot"
echo "Testing ${openapi} with ${RULESET}. The output will be compared to ${snapshot}.snapshot"

spectral lint -r "${RULESET}" -D "${openapi}" | \
diff -u --color - "${snapshot}.snapshot"
}

snapshot(){
Expand All @@ -28,7 +30,9 @@ snapshot(){
exit 1
fi

spectral lint -r "${RULESET}" -D -F warn "${openapi}" > "${snapshot}.snapshot"
echo "Snapshotting ${openapi} with ${RULESET}. The output will saved as ${snapshot}.snapshot"

spectral lint -r "${RULESET}" -D "${openapi}" > "${snapshot}.snapshot"
}


Expand Down
1 change: 1 addition & 0 deletions rules-modi
Submodule rules-modi added at b21f74
63 changes: 0 additions & 63 deletions rules/cache-control.yml

This file was deleted.

68 changes: 0 additions & 68 deletions rules/casing.yml

This file was deleted.

45 changes: 0 additions & 45 deletions rules/headers.yml

This file was deleted.

64 changes: 0 additions & 64 deletions rules/httpbis.yml

This file was deleted.

35 changes: 0 additions & 35 deletions rules/https.yml

This file was deleted.

Loading

0 comments on commit a9f7636

Please sign in to comment.