diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7cfb627095d97fa1ed54a7ab418b15c8e38abb06..38fb1ba5e34f54551238a3ee4d097d410673bda0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,42 +15,40 @@ workflow: - if: '$CI_COMMIT_TAG' stages: - - lint - build + - lint - upload +build: + stage: build + image: $CI_REGISTRY/node:current-alpine + before_script: + - npm install -g @apidevtools/swagger-cli + - mkdir dist + script: + - swagger-cli bundle -t yaml -o dist/submission-api.yaml spec/submission-api.yaml + artifacts: + expose_as: 'Built API spec' + paths: + - dist/ + expire_in: 30 days + lint: stage: lint image: name: $CI_REGISTRY/stoplight/spectral:5 entrypoint: [ "" ] script: - - spectral lint spec/*.yaml -D + - spectral lint dist/submission-api.yaml -D openapi4j-parser: stage: lint image: $CI_REGISTRY/node:current-buster before_script: - - npm install -g @apidevtools/swagger-cli - export DEBIAN_FRONTEND=noninteractive - apt-get update && apt-get install -y openjdk-11-jre script: - - swagger-cli bundle -t yaml -o "spec/submission-api-bundled.yaml" "spec/submission-api.yaml" - - java -jar openapi4j-parser-cli-1.0.0.jar "spec/submission-api-bundled.yaml" - -build: - stage: build - image: $CI_REGISTRY/node:current-alpine - before_script: - - npm install -g @apidevtools/swagger-cli - - mkdir dist - script: - - swagger-cli bundle -t yaml -o dist/submission-api.yaml spec/submission-api.yaml - artifacts: - expose_as: 'Built API spec' - paths: - - dist/ - expire_in: 30 days + - java -jar openapi4j-parser-cli-1.0.0.jar "dist/submission-api.yaml" upload:latest: stage: upload diff --git a/.spectral.yml b/.spectral.yml index c7be1e0099b46110e5ef9b3b54dd97a9b9b7ed39..98f6fa9460ddbbd6d1c447b2e3e193bec92aa39a 100644 --- a/.spectral.yml +++ b/.spectral.yml @@ -32,3 +32,45 @@ rules: - $.paths.*[get] then: function: pagination-response + patch-without-request-body: # Remove once upstream ruleset is fixed (https://github.com/italia/api-oas-checker/pull/454) + description: |- + The PATCH method requests that a set of changes described in the + `requestBody` be applied to the target resource. + A PATCH specification without a `requestBody` + just applies no changes to the target resource. + + Since PATCH has impacts on caches, using it + on a different target resource may result in non-interoperable + behavior. + + For example, to modify the resource at `/user/123`, + you can use the following PATCH request: + + ``` + PATCH /user/123 + Content-Type: application/json-patch + + {"op": "replace", "path": "enable", "value": true} + ``` + + or POST request with the semantic implied by the target url: + + ``` + POST /user/123/enable + ``` + + Instead, the following request + is expected to modify the `/user/123/enable` + subresource, and not the `/user/123` one. + + ``` + PATCH /user/123/enable + ```` + message: PATCH requires a non empty requestBody. + severity: error + given: $.paths.*.patch + then: + - field: requestBody + function: defined + - field: requestBody.required + function: truthy diff --git a/tag.sh b/tag.sh index 5cd4bf3ea7557bc0ca3c8955007d170881b0def4..6522ecae9e2e65d8fada21a3d8b1010ae6a2da6d 100755 --- a/tag.sh +++ b/tag.sh @@ -6,8 +6,11 @@ if [ -z "$TAG" ]; then echo "Usage: $0 TAG" echo "Example: $0 1.0.1" - echo "Existing tags:" - PAGER= git tag --list | sed 's/^/ /' + echo "The latest 10 existing tags:" + git tag --list \ + | grep '^[0-9]' \ + | sort --version-sort \ + | tail exit 1 fi diff --git a/validate.sh b/validate.sh index a7e64d6f25360a64da5d5e0dcca1528ac1aa8752..1e267b22a741cf3743037431f59e532c9b2c84b7 100755 --- a/validate.sh +++ b/validate.sh @@ -9,7 +9,7 @@ YML_IN="spec/submission-api-bundled.yaml" docker run --rm -v "$(pwd):/work" jeanberu/swagger-cli \ swagger-cli validate "/work/$YML_IN" -docker run --rm -v "$(pwd):/work" -w /work stoplight/spectral \ +docker run --rm -v "$(pwd):/work" -w /work stoplight/spectral:5 \ lint "/work/$YML_IN" -D java -jar openapi4j-parser-cli-1.0.0.jar "$YML_IN"