Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client generation #4366

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
90 changes: 0 additions & 90 deletions scripts/openapi-generator.bash

This file was deleted.

56 changes: 28 additions & 28 deletions services/api-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,22 @@ run-fake-devel: # starts a fake server in a dev-container


# BUILD ###########################################################################
# specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator)
OPENAPI_GENERATOR_NAME := itisfoundation/openapi-generator-cli-openapi-generator-v4.2.3
OPENAPI_GENERATOR_TAG := v0
OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG)

define create_and_validate_openapi
# generating openapi specs file under $< (NOTE: Skips DEV FEATURES since this OAS is the 'offically released'!)
@source .env; \
export API_SERVER_DEV_FEATURES_ENABLED=$1; \
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@

# validates OAS file: $@
@set -o allexport; \
source .env; \
cd $(CURDIR); \
$(SCRIPTS_DIR)/openapi-generator.bash validate --input-spec /local/$@
docker run --rm \
--volume "$(CURDIR):/local" \
$(OPENAPI_GENERATOR_IMAGE) validate --input-spec /local/$@

endef


Expand All @@ -108,7 +113,7 @@ openapi-dev.json: .env
@$(call create_and_validate_openapi,1)

# GENERATION python client ###########################################################################
.PHONY: python-client generator-help fetch-openapi-templates
.PHONY: python-client generator-help python-client-openapi-branch

# SEE https://openapi-generator.tech/docs/usage#generate
# SEE https://openapi-generator.tech/docs/generators/python
Expand All @@ -118,16 +123,15 @@ openapi-dev.json: .env
#
# NOTE: assumes this repo exists
GIT_USER_ID := ITISFoundation
GIT_REPO_ID := osparc-simcore-python-client

GIT_CLIENT_REPO_ID := osparc-simcore-python-client
GIT_OPENAPI_REPO_ID := openapi-generator
GENERATOR_NAME := python

ADDITIONAL_PROPS := \
generateSourceCodeOnly=false\
hideGenerationTimestamp=true\
library=urllib3\
packageName=osparc\
packageUrl=https://github.com/$(GIT_USER_ID)/${GIT_REPO_ID}.git\
packageUrl=https://github.com/$(GIT_USER_ID)/${GIT_CLIENT_REPO_ID}.git\
packageVersion=$(APP_VERSION)\
projectName=osparc-simcore-python-api
ADDITIONAL_PROPS := $(foreach prop,$(ADDITIONAL_PROPS),$(strip $(prop)))
Expand All @@ -136,12 +140,9 @@ null :=
space := $(null) #
comma := ,

CONTAINER_TEMPL_DIR := /tmp/openapi_templates


client:
# cloning $(GIT_USER_ID)/$(GIT_REPO_ID) -> $@
git clone [email protected]:$(GIT_USER_ID)/$(GIT_REPO_ID).git $@
# cloning $(GIT_USER_ID)/$(GIT_CLIENT_REPO_ID) -> $@
git clone [email protected]:$(GIT_USER_ID)/$(GIT_CLIENT_REPO_ID).git $@
# TODO: if fails, add -b
cd client; git checkout -b "upgrade-${APP_VERSION}"

Expand All @@ -150,20 +151,19 @@ python-client: client openapi.json ## runs python client generator
@cp openapi.json client/api/
# generates
@source .env; \
cd $(CURDIR); \
$(SCRIPTS_DIR)/openapi-generator.bash generate \
--generator-name=$(GENERATOR_NAME) \
--git-user-id=$(GIT_USER_ID) \
--git-repo-id=$(GIT_REPO_ID) \
--http-user-agent="osparc-api/$(APP_VERSION)/python" \
--input-spec=/local/openapi.json \
--output=/local/client \
--additional-properties=$(subst $(space),$(comma),$(strip $(ADDITIONAL_PROPS))) \
--package-name=osparc \
--release-note="Updated to $(APP_VERSION)"
docker run --rm \
--volume "$(CURDIR):/local" \
$(OPENAPI_GENERATOR_IMAGE) generate \
--generator-name=$(GENERATOR_NAME) \
--git-user-id=$(GIT_USER_ID) \
--git-repo-id=$(GIT_CLIENT_REPO_ID) \
--http-user-agent="osparc-api/$(APP_VERSION)/python" \
--input-spec=/local/openapi.json \
--output=/local/client \
--additional-properties=$(subst $(space),$(comma),$(strip $(ADDITIONAL_PROPS))) \
--package-name=osparc \
--release-note="Updated to $(APP_VERSION)"

generator-help: ## help on client-api generator
# generate help
@$(SCRIPTS_DIR)/openapi-generator-cli.bash help generate
# generator config help
@$(SCRIPTS_DIR)/openapi-generator-cli.bash config-help -g $(GENERATOR_NAME)
@docker run --rm $(OPENAPI_GENERATOR_IMAGE) help generate