Skip to content

Commit

Permalink
Rework fixing api spec
Browse files Browse the repository at this point in the history
This also allows to consume the *api.json from anywhere, as it's
processed into patched-api.json prior to be used in the container.

[noissue]
  • Loading branch information
mdellweg committed Jun 26, 2024
1 parent 4b517f4 commit 697993f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 73 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulp_file' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template
---
name: pulp-openapi-generator PR CI
on: pull_request
Expand Down Expand Up @@ -66,7 +60,7 @@ jobs:
run: |
echo ::group::HTTPIE
sudo apt-get update -yq
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install httpie
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install httpie jq
echo ::endgroup::
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/.ci/assets/httpie/" >> $GITHUB_ENV
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ target/
#Ipython Notebook
.ipynb_checkpoints

# written in generate.sh
.openapi-generator-ignore

# generated client packages
# generated stuff
/api.json
/patched-api.json
/*-client/
.openapi-generator-ignore
19 changes: 15 additions & 4 deletions gen-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,23 @@ else
VOLUME_DIR="${PWD}"
fi

REMOVE_COOKIE_AUTH_FILTER='del(.paths[][].security|select(.)[]|select(.cookieAuth))|del(.components.securitySchemes.cookieAuth)'

# These two may be needed when upgrading the generator image
FIX_TASK_CREATED_RESOURCES_FILTER='(.components.schemas.TaskResponse|select(.)|.properties.created_resources.items) |= {"$oneOf":[{type:"null"},.]}'
FIX_TASK_ERROR_FILTER='(.components.schemas.TaskResponse|select(.)|.properties.error) |= (del(.readOnly) | .additionalProperties.type = "string")'

if [ "$LANGUAGE" = "python" ]
then
cat "${API_SPEC}" | jq "." > patched-api.json

$CONTAINER_EXEC run \
"${ULIMIT_COMMAND[@]}" \
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_PYTHON_IMAGE" generate \
-i "${VOLUME_DIR}/${API_SPEC}" \
-i "${VOLUME_DIR}/patched-api.json" \
-g python \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
"--additional-properties=packageName=pulpcore.client.${PACKAGE},projectName=${PACKAGE}-client,packageVersion=${VERSION},domainEnabled=${DOMAIN_ENABLED}" \
Expand All @@ -86,14 +94,15 @@ then
mkdir -p "${PACKAGE}-client"
echo git_push.sh > "${PACKAGE}-client/.openapi-generator-ignore"

python3 remove-cookie-auth.py
cat "${API_SPEC}" | jq "${REMOVE_COOKIE_AUTH_FILTER}" > patched-api.json

$CONTAINER_EXEC run \
"${ULIMIT_COMMAND[@]}" \
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_RUBY_IMAGE" generate \
-i "${VOLUME_DIR}/${API_SPEC}" \
-i "${VOLUME_DIR}/patched-api.json" \
-g ruby \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
"--additional-properties=gemName=${PACKAGE}_client,gemLicense="GPLv2+",gemVersion=${VERSION},gemHomepage=https://github.com/pulp/${PACKAGE}" \
Expand All @@ -105,13 +114,15 @@ fi

if [ "$LANGUAGE" = "typescript" ]
then
cat "${API_SPEC}" | jq "." > patched-api.json

$CONTAINER_EXEC run \
"${ULIMIT_COMMAND[@]}" \
"${USER_COMMAND[@]}" \
--rm \
"${VOLUME_OPTION[@]}" \
"$OPENAPI_TYPESCRIPT_IMAGE" generate \
-i "${VOLUME_DIR}/${API_SPEC}" \
-i "${VOLUME_DIR}/patched-api.json" \
-g typescript-axios \
-o "${VOLUME_DIR}/${PACKAGE}-client" \
-t "${VOLUME_DIR}/templates/typescript-axios" \
Expand Down
58 changes: 0 additions & 58 deletions remove-cookie-auth.py

This file was deleted.

0 comments on commit 697993f

Please sign in to comment.