Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/spectral #118

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Lint with spectral
run: npm install && npm run spectral
- name: Build with Maven
run: mvn clean verify --file pom.xml
4 changes: 3 additions & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .spectral.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends: spectral:oas
functions: [x-header-parameter]
rules:
wrong-version:
description: OpenApi version must be 3.x.x
given: $.openapi
severity: error
then:
field: "@value"
function: pattern
functionOptions:
match: "^3\.\d\.\d+$"
x-header-not-set:
message: "{{error}}"
given: $.paths.*.post
severity: error
then:
function: "x-header-parameter"
functionOptions:
value: "test"
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ Note: _(One must have issued `npm install` previously.)_
Run e.g. on master: `mvn -B release:prepare` e.g. via [![Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io#https://github.com/baloise/corellia)

Subsequently the GitHub action worksflow "create release" will pick up the published tag and release and deploy the artifacts in the Github package registry.


## Spectral linting (just to not forget how to do it.)

use the following comand to lint openapi.json
```
node run spectral
```
`.spectral` contains the rules and `functions/` contains the custom functions used in the rule

Custom example rules are:
- Version must be 3.0.1
- all post actions must have X-Caller-Name and X-EventId in the header

All standard rules for openapie 3 are usesd as well.

Documentation can be found here:
https://meta.stoplight.io/docs/spectral/README.md

`docker run --rm -it -v %cd%:/tmp quay.balgroupit.com/baloise-base-images/spectral lint /tmp/docs/openapi.json --ruleset=/tmp/docs/spectral.yaml`
2 changes: 1 addition & 1 deletion docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
"properties" : {
"data" : {
"type" : "array",
"description" : "The document itself. If the documentType is CONTRACT then the document must contain one of these keywords 'Versicherungsvertrag, Contrat d�assurance, Contratto di assicurazione, Insurance policy'",
"description" : "The document itself. If the documentType is CONTRACT then the document must contain one of these keywords 'Versicherungsvertrag, Contrat d�assurance, Contratto di assicurazione, Insurance policy'",
"items" : {
"type" : "string",
"format" : "byte"
Expand Down
10 changes: 10 additions & 0 deletions functions/x-header-parameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = (targetVal, opts) => {
if ((targetVal.parameters.filter(param => param.name == "X-Caller-Name").length == 0)
|| (targetVal.parameters.filter(param => param.name == "X-Event-ID").length == 0)) {
return [
{
message: 'Header must have X-Caller-Name and X-Event-Id set in operation: ' + targetVal.operationId,
},
];
}
};
Loading