From 7c7478ccc3c6b3ba263f2224b7d3cdba71122904 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Sat, 13 Jan 2024 14:06:13 +0700 Subject: [PATCH 1/8] feat: add openapi linter --- catalyst-gateway/.spectral.yml | 12 ++++++++++++ catalyst-gateway/Earthfile | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 catalyst-gateway/.spectral.yml diff --git a/catalyst-gateway/.spectral.yml b/catalyst-gateway/.spectral.yml new file mode 100644 index 00000000000..d8667163a51 --- /dev/null +++ b/catalyst-gateway/.spectral.yml @@ -0,0 +1,12 @@ +# References to the rules +# OpenAPI: https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#openapi-rules +# OWASP Top 10: https://apistylebook.stoplight.io/docs/owasp-top-10 +# Documentations: https://github.com/stoplightio/spectral-documentation/blob/main/src/ruleset.ts + +# cspell: words OWASP owasp + +# Use CDN hosted version for spectral-documentation and spectral-owasp +extends: +- 'spectral:oas' +- 'https://unpkg.com/@stoplight/spectral-documentation/dist/ruleset.mjs' +- 'https://unpkg.com/@stoplight/spectral-owasp-ruleset/dist/ruleset.mjs' diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index e70fb1e480e..53d0c35040c 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -121,3 +121,9 @@ local-ci-run: # BUILD +package BUILD +test # BUILD +publish + +# check-lint-openapi - OpenAPI linting from a given directory +check-lint-openapi: + FROM busybox + COPY +hosted-build/doc ./work + DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir="./work" --file_type="json" From add302db438db2e4bbd51d80869d9955cf0231cc Mon Sep 17 00:00:00 2001 From: bkioshn Date: Tue, 16 Jan 2024 13:15:41 +0700 Subject: [PATCH 2/8] fix(lint): openapi linting --- catalyst-gateway/Earthfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index 53d0c35040c..ec91d09309a 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -122,8 +122,9 @@ local-ci-run: BUILD +test # BUILD +publish -# check-lint-openapi - OpenAPI linting from a given directory -check-lint-openapi: - FROM busybox - COPY +hosted-build/doc ./work - DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir="./work" --file_type="json" +check-lint-openapi: + FROM github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+spectral-base + # Copy the doc artifact. + COPY +hosted-build/doc ./doc + # Scan the doc directory where type of file is JSON. + DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir=./doc --file_type="json" From e7b6d3ba8bdb5a9efb6abbc18781d3d360e49f86 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Tue, 16 Jan 2024 20:11:59 +0700 Subject: [PATCH 3/8] fix(spectral): add version for CDN --- catalyst-gateway/.spectral.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catalyst-gateway/.spectral.yml b/catalyst-gateway/.spectral.yml index d8667163a51..556d9a008d4 100644 --- a/catalyst-gateway/.spectral.yml +++ b/catalyst-gateway/.spectral.yml @@ -8,5 +8,5 @@ # Use CDN hosted version for spectral-documentation and spectral-owasp extends: - 'spectral:oas' -- 'https://unpkg.com/@stoplight/spectral-documentation/dist/ruleset.mjs' -- 'https://unpkg.com/@stoplight/spectral-owasp-ruleset/dist/ruleset.mjs' +- 'https://unpkg.com/@stoplight/spectral-documentation@1.3.1/dist/ruleset.mjs' +- 'https://unpkg.com/@stoplight/spectral-owasp-ruleset@1.4.3/dist/ruleset.mjs' From 9272740d6d9e9ab5e2f68affe818c618b9a36877 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Tue, 16 Jan 2024 20:16:49 +0700 Subject: [PATCH 4/8] fix(openapi): linting openAPI files in test stage --- catalyst-gateway/Earthfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index ec91d09309a..8e8b7a4660a 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -108,6 +108,15 @@ test: BUILD --platform=linux/amd64 ./tests+integration-test END +# test-lint-openapi - OpenAPI linting from an artifact +# testing whether the OpenAPI generated during build stage follows good practice. +test-lint-openapi: + FROM github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+spectral-base + # Copy the doc artifact. + COPY +hosted-build/doc ./doc + # Scan the doc directory where type of file is JSON. + DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir=./doc --file_type="json" + # Publish packages if all integration tests have passed. (Failure to pass tests will prevent packages being published.) # publish: # FROM scratch @@ -122,9 +131,3 @@ local-ci-run: BUILD +test # BUILD +publish -check-lint-openapi: - FROM github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+spectral-base - # Copy the doc artifact. - COPY +hosted-build/doc ./doc - # Scan the doc directory where type of file is JSON. - DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir=./doc --file_type="json" From b0b1884c3d82a6c8add809f8e200031eed1b3fa9 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Wed, 17 Jan 2024 15:47:18 +0700 Subject: [PATCH 5/8] fix: make the info section compatible with v3.0.0 --- catalyst-gateway/bin/src/service/api/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/catalyst-gateway/bin/src/service/api/mod.rs b/catalyst-gateway/bin/src/service/api/mod.rs index a093589b448..0764e21ac4d 100644 --- a/catalyst-gateway/bin/src/service/api/mod.rs +++ b/catalyst-gateway/bin/src/service/api/mod.rs @@ -31,9 +31,6 @@ fn get_api_contact() -> ContactObject { .url("https://projectcatalyst.io") } -/// A summary describing the API -const API_SUMMARY: &str = "Project Catalyst Gateway API"; - /// A long description of the API. Markdown is supported const API_DESCRIPTION: &str = r#"# Catalyst Gateway API. @@ -53,7 +50,6 @@ TODO: fn get_api_license() -> LicenseObject { LicenseObject::new("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0") - .identifier("Apache-2.0") } /// Get the terms of service for the API @@ -72,7 +68,6 @@ pub(crate) fn mk_api( .contact(get_api_contact()) .description(API_DESCRIPTION) .license(get_api_license()) - .summary(API_SUMMARY) .terms_of_service(TERMS_OF_SERVICE) .url_prefix(API_URL_PREFIX.as_str()); From c931b4673c51640bef23e1a9b87e7a8accdccd2c Mon Sep 17 00:00:00 2001 From: bkioshn Date: Wed, 17 Jan 2024 15:55:28 +0700 Subject: [PATCH 6/8] style: format rust --- catalyst-gateway/bin/src/service/api/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/catalyst-gateway/bin/src/service/api/mod.rs b/catalyst-gateway/bin/src/service/api/mod.rs index 0764e21ac4d..ed573a9ae75 100644 --- a/catalyst-gateway/bin/src/service/api/mod.rs +++ b/catalyst-gateway/bin/src/service/api/mod.rs @@ -48,8 +48,7 @@ TODO: /// Get the license details for the API fn get_api_license() -> LicenseObject { - LicenseObject::new("Apache 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0") + LicenseObject::new("Apache 2.0").url("https://www.apache.org/licenses/LICENSE-2.0") } /// Get the terms of service for the API From 90666df189b058b65ed7da6612178e9037141819 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Wed, 17 Jan 2024 16:23:47 +0700 Subject: [PATCH 7/8] fix: remove openapi linter --- catalyst-gateway/.spectral.yml | 12 ------------ catalyst-gateway/Earthfile | 9 --------- 2 files changed, 21 deletions(-) delete mode 100644 catalyst-gateway/.spectral.yml diff --git a/catalyst-gateway/.spectral.yml b/catalyst-gateway/.spectral.yml deleted file mode 100644 index 556d9a008d4..00000000000 --- a/catalyst-gateway/.spectral.yml +++ /dev/null @@ -1,12 +0,0 @@ -# References to the rules -# OpenAPI: https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#openapi-rules -# OWASP Top 10: https://apistylebook.stoplight.io/docs/owasp-top-10 -# Documentations: https://github.com/stoplightio/spectral-documentation/blob/main/src/ruleset.ts - -# cspell: words OWASP owasp - -# Use CDN hosted version for spectral-documentation and spectral-owasp -extends: -- 'spectral:oas' -- 'https://unpkg.com/@stoplight/spectral-documentation@1.3.1/dist/ruleset.mjs' -- 'https://unpkg.com/@stoplight/spectral-owasp-ruleset@1.4.3/dist/ruleset.mjs' diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index 8e8b7a4660a..51f4be73f05 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -108,15 +108,6 @@ test: BUILD --platform=linux/amd64 ./tests+integration-test END -# test-lint-openapi - OpenAPI linting from an artifact -# testing whether the OpenAPI generated during build stage follows good practice. -test-lint-openapi: - FROM github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+spectral-base - # Copy the doc artifact. - COPY +hosted-build/doc ./doc - # Scan the doc directory where type of file is JSON. - DO github.com/input-output-hk/catalyst-ci/earthly/spectral:feat/openapi-lint+BUILD_SPECTRAL --dir=./doc --file_type="json" - # Publish packages if all integration tests have passed. (Failure to pass tests will prevent packages being published.) # publish: # FROM scratch From e5b655dd48e1b06f669e2ec611573a82ad80f6af Mon Sep 17 00:00:00 2001 From: bkioshn Date: Wed, 17 Jan 2024 16:27:11 +0700 Subject: [PATCH 8/8] style: remove EOF line --- catalyst-gateway/Earthfile | 1 - 1 file changed, 1 deletion(-) diff --git a/catalyst-gateway/Earthfile b/catalyst-gateway/Earthfile index 51f4be73f05..e70fb1e480e 100644 --- a/catalyst-gateway/Earthfile +++ b/catalyst-gateway/Earthfile @@ -121,4 +121,3 @@ local-ci-run: # BUILD +package BUILD +test # BUILD +publish -