From fd1e06049f369ac4a36cd293fe8529a4289e8846 Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 22 May 2023 17:46:09 -0400 Subject: [PATCH] Use redocly/cli to bundle/lint OpenAPI spec --- .github/workflows/pipeline.yml | 16 +++++++++++++--- Makefile | 14 +++++++------- api/spec.yml | 4 ++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index bc7b41d67..426deaa9a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -110,7 +110,7 @@ jobs: path: ui/build api: - name: Test and build API spec + name: Build OpenAPI spec runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -120,7 +120,17 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - - run: make testapi + - run: make lintapi + + - run: make gen + + - name: Verify no changes + run: | + git status --porcelain + if [ -n "$(git status --porcelain)" ]; then + echo 'Changes to OpenAPI spec caused changes to the code. Please review and commit the changes.' + exit 1 + fi - uses: actions/upload-artifact@v3 with: @@ -129,7 +139,7 @@ jobs: binaries: name: Build binaries - needs: [js, go, go-lint] + needs: [js, go, go-lint, api] runs-on: ubuntu-latest steps: - name: Checkout Code diff --git a/Makefile b/Makefile index de9efaf2a..eb3b05df0 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,7 @@ test: ##@Development Run Go tests go test -race -shuffle=on ./... .PHONY: test -testapi: api/openapi.yaml ##@Development Validate OpenAPI spec - @npx swagger-cli validate api/openapi.yaml -.PHONY: testapi - -testall: testapi test ##@Development Run Go and JS tests, and validate OpenAPI spec +testall: test ##@Development Run Go and JS tests, and validate OpenAPI spec @(cd ./ui && npm test -- --watchAll=false) .PHONY: testall @@ -44,7 +40,11 @@ lint: ##@Development Lint Go code go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v --timeout 5m .PHONY: lint -lintall: lint ##@Development Lint Go and JS code +lintapi: api/openapi.yaml ##@Development Lint OpenAPI spec + npx @redocly/cli lint api/openapi.yaml +.PHONY: lintapi + +lintall: lint lintapi ##@Development Lint Go and JS code @(cd ./ui && npm run check-formatting) || (echo "\n\nPlease run 'npm run prettier' to fix formatting issues." && exit 1) @(cd ./ui && npm run lint) .PHONY: lintall @@ -60,7 +60,7 @@ api: check_go_env api/openapi.yaml spec_parts=$(shell find api -name '*.yml') api/openapi.yaml: $(spec_parts) @echo "Bundling OpenAPI spec..." - npx swagger-cli bundle api/spec.yml --outfile api/openapi.yaml --type yaml + npx @redocly/cli bundle api/spec.yml -o api/openapi.yaml snapshots: ##@Development Update (GoLang) Snapshot tests UPDATE_SNAPSHOTS=true go run github.com/onsi/ginkgo/v2/ginkgo@latest ./server/subsonic/... diff --git a/api/spec.yml b/api/spec.yml index d47cccb39..58f671aad 100644 --- a/api/spec.yml +++ b/api/spec.yml @@ -12,6 +12,10 @@ info: contact: name: Navidrome url: https://navidrome.org + license: + name: GNU General Public License v3.0 + url: https://github.com/navidrome/navidrome/blob/master/LICENSE + servers: - url: /api/v2