From 2d28d88aa9e1e131f868768e189eededa81e8c7a Mon Sep 17 00:00:00 2001 From: Nikolay Mitrofanov Date: Thu, 2 Jul 2026 20:42:29 +0300 Subject: [PATCH 1/2] upgrade makefile-common to v0.3.0 --- .gitignore | 2 +- makefile-common | 2 +- openapi.mk | 56 +++++++++++++++++++++++-------------------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 7f659a9..df692e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ bin/ - +build/ tmp-openapi/ diff --git a/makefile-common b/makefile-common index 46f9688..b992199 160000 --- a/makefile-common +++ b/makefile-common @@ -1 +1 @@ -Subproject commit 46f9688546c02d04cd3017508d7454092258786b +Subproject commit b992199bde2277c477823a40e0b9e493fa853a12 diff --git a/openapi.mk b/openapi.mk index 8d5efd2..cdf31ed 100644 --- a/openapi.mk +++ b/openapi.mk @@ -1,59 +1,53 @@ OPENAPI_CONVERTER_VERSION = v1.0.5 -##@ Openapi +##@ OpenAPI openapi/update/spec: check/installed/curl install/yq ## Download spec and convert to json - ##~ SPEC_URL=URL - URL to download spec - ##~ OUT_PATH=PATH - output file - @if [ -z "$$SPEC_URL" ]; then \ - echo -e "${RED_COLOR}Spec url not passed with env SPEC_URL${NO_COLOR}"; \ - exit 1; \ + @##~ SPEC_URL=URL - URL to download spec + @##~ OUT_PATH=PATH - output file + @${INCLUDE_ECHO} \ + if [ -z "$$SPEC_URL" ]; then \ + exit_with_err "Spec url not passed with env SPEC_URL"; \ fi; \ if [ -z "$$OUT_PATH" ]; then \ - echo -e "${RED_COLOR}Out spec file not passed with env OUT_PATH${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Out spec file not passed with env OUT_PATH"; \ fi; \ dir_path="$$(dirname "$$OUT_PATH")"; \ if ! dir_path="$$(realpath "$$dir_path")"; then \ - echo -e "${RED_COLOR}Cannot get real path for $$OUT_PATH${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Cannot get real path for $$OUT_PATH"; \ fi; \ if [ ! -d "$$dir_path" ]; then \ - echo -e "${RED_COLOR}$$dir_path out put dir is not exists${NO_COLOR}"; \ - exit 1; \ + exit_with_err "$$dir_path out put dir is not exists"; \ fi; \ set -Eeuo pipefail; \ yaml_tmp="$$(mktemp)"; \ curl -sSfLo "$$yaml_tmp" "$$SPEC_URL"; \ - cat "$$yaml_tmp" | "$(YQ_BIN_FULL)" -o=json -r . > "$(OUT_PATH)" + cat "$$yaml_tmp" | "$(YQ_BIN_FULL)" -o=json -r . > "$(OUT_PATH)"; \ + rm -f "$$yaml_tmp" openapi/convert/to/v3: check/installed/docker check/installed/curl ## Convert opeanapi spec v2 to v3 - ##~ INPUT_SPEC=PATH - Path to v2 spec - ##~ OUT_SPEC_PATH=PATH - Output v3 spec file - @if [ -z "$$INPUT_SPEC" ]; then \ - echo -e "${RED_COLOR}Input spec path not passed with env INPUT_SPEC${NO_COLOR}"; \ - exit 1; \ + @##~ INPUT_SPEC=PATH - Path to v2 spec + @##~ OUT_SPEC_PATH=PATH - Output v3 spec file + @${INCLUDE_ECHO} \ + if [ -z "$$INPUT_SPEC" ]; then \ + exit_with_err "Input spec path not passed with env INPUT_SPEC"; \ fi; \ if [ ! -f "$$INPUT_SPEC" ]; then \ - echo -e "${RED_COLOR}Input spec $$INPUT_SPEC is not file${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Input spec $$INPUT_SPEC is not file"; \ fi; \ if [ -z "$$OUT_SPEC_PATH" ]; then \ - echo -e "${RED_COLOR}Out spec path not passed with env OUT_SPEC_PATH${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Out spec path not passed with env OUT_SPEC_PATH"; \ fi; \ dir_path="$$(dirname "$$OUT_SPEC_PATH")"; \ if ! dir_path="$$(realpath "$$dir_path")"; then \ - echo -e "${RED_COLOR}Cannot get real path for $$OUT_SPEC_PATH${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Cannot get real path for $$OUT_SPEC_PATH"; \ fi; \ if [ ! -d "$$dir_path" ]; then \ - echo -e "${RED_COLOR}$$dir_path out put dir is not exists${NO_COLOR}"; \ + exit_with_err "$$dir_path out put dir is not exists"; \ exit 1; \ fi; \ if ! cid="$$(docker run --rm -d -p 26080:8080 --name swagger-converter swaggerapi/swagger-converter:$(OPENAPI_CONVERTER_VERSION))"; then \ - echo -e "${RED}Converter container should not start${NO_COLOR}"; \ - exit 1; \ + exit_with_err "Converter container should not start"; \ fi; \ echo "Converter container $$cid available on http://127.0.0.1:26080 Sleep 10s for init..."; \ sleep 10; \ @@ -66,12 +60,12 @@ openapi/convert/to/v3: check/installed/docker check/installed/curl ## Convert op http://127.0.0.1:26080/api/convert > $(OUT_SPEC_PATH) ; \ then \ is_error="true"; \ - echo -e "${RED}Convert failed${NO_COLOR}"; \ + echo_err "Convert failed"; \ fi; \ echo "Stop converter container $$cid ..."; \ if ! docker stop "$$cid"; then \ is_error="true"; \ - echo -e "${RED}Container $$cid was not stopped!${NO_COLOR}"; \ + echo_err "Container $$cid was not stopped!"; \ fi; \ if [ "$$is_error" = "true" ]; then \ exit 1; \ @@ -80,4 +74,6 @@ openapi/convert/to/v3: check/installed/docker check/installed/curl ## Convert op _OPENAPI_ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) openapi/check/gitignore: export GITIGNORES_WITH_REQUIRED_RULES = $(_OPENAPI_ROOT_DIR)/makefile-common/.gitignore -openapi/check/gitignore: check/common/gitignore ## Check that .gitignore up to date with makefile-inc/common \ No newline at end of file +openapi/check/gitignore: common/git/check/gitignore ## Check that .gitignore up to date with makefile-inc/common + +.PHONY: openapi/update/spec openapi/convert/to/v3 openapi/check/gitignore \ No newline at end of file From 9a5fe24b5757c5e60dfd401eaccdb43d3c0b594f Mon Sep 17 00:00:00 2001 From: Nikolay Mitrofanov Date: Thu, 2 Jul 2026 21:21:05 +0300 Subject: [PATCH 2/2] ++ --- README.md | 20 +++++++++++++++++--- makefile-common | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5e57af8..04d2126 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # openapi -Makefiles includes for generations client and servers and convertions openapi specs. +Makefiles includes for generations client and servers and conversions openapi specs. ## Deps @@ -24,7 +24,7 @@ Add submodule: git submodule add git@github.com:makefile-inc/openapi.git makefile-openapi ``` -Checkout to target wersion: +Checkout to target version: ``` pushd . @@ -39,6 +39,20 @@ Include in root Makefile in the next way: include $(CURDIR)/makefile-openapi/include.mk.inc ``` +**WARNING! If you use submodule and github actions, add to checkout action checkout submodules `submodules: "true"`, like:** +```yaml +... + steps: + - &checkout_step + name: Checkout + uses: actions/checkout@v6.0.2 + with: + fetch-depth: 0 + submodules: "true" + ref: ${{ github.event.pull_request.head.sha }} +... +``` + ## Targets - `openapi/update/spec` - download spec and convert to json @@ -58,7 +72,7 @@ include $(CURDIR)/makefile-openapi/include.mk.inc make openapi/convert/to/v3 INPUT_SPEC=tmp-openapi/v2-1.json OUT_SPEC_PATH=tmp-openapi/v3-1.json ``` - `openapi/check/gitignore` - Check that .gitignore up to date with makefile-inc/common - Userfull for check up to date root .gitignore with makefile-inc/common during update. + Usefully for check up to date root .gitignore with makefile-inc/common during update. ### Example diff --git a/makefile-common b/makefile-common index b992199..81b9298 160000 --- a/makefile-common +++ b/makefile-common @@ -1 +1 @@ -Subproject commit b992199bde2277c477823a40e0b9e493fa853a12 +Subproject commit 81b9298201c5c0c1ef9372745d2302d7bd21f77b