Skip to content
Merged
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bin/

build/
tmp-openapi/
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 .
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion makefile-common
Submodule makefile-common updated 8 files
+1 −1 .gitignore
+70 −76 00-common.mk
+1 −1 01-duration.mk
+146 −0 02-git.mk
+214 −69 04-bin.mk
+181 −0 05-build.mk
+172 −1 Makefile
+238 −34 README.md
56 changes: 26 additions & 30 deletions openapi.mk
Original file line number Diff line number Diff line change
@@ -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; \
Expand All @@ -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; \
Expand All @@ -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
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