Skip to content

Commit 697993f

Browse files
committed
Rework fixing api spec
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]
1 parent 4b517f4 commit 697993f

File tree

4 files changed

+20
-73
lines changed

4 files changed

+20
-73
lines changed

.github/workflows/ci.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# WARNING: DO NOT EDIT!
2-
#
3-
# This file was generated by plugin_template, and is managed by it. Please use
4-
# './plugin-template --github pulp_file' to update this file.
5-
#
6-
# For more info visit https://github.com/pulp/plugin_template
71
---
82
name: pulp-openapi-generator PR CI
93
on: pull_request
@@ -66,7 +60,7 @@ jobs:
6660
run: |
6761
echo ::group::HTTPIE
6862
sudo apt-get update -yq
69-
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install httpie
63+
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install httpie jq
7064
echo ::endgroup::
7165
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/.ci/assets/httpie/" >> $GITHUB_ENV
7266

.gitignore

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ target/
6363
#Ipython Notebook
6464
.ipynb_checkpoints
6565

66-
# written in generate.sh
67-
.openapi-generator-ignore
68-
69-
# generated client packages
66+
# generated stuff
67+
/api.json
68+
/patched-api.json
7069
/*-client/
70+
.openapi-generator-ignore

gen-client.sh

+15-4
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,23 @@ else
6161
VOLUME_DIR="${PWD}"
6262
fi
6363

64+
REMOVE_COOKIE_AUTH_FILTER='del(.paths[][].security|select(.)[]|select(.cookieAuth))|del(.components.securitySchemes.cookieAuth)'
65+
66+
# These two may be needed when upgrading the generator image
67+
FIX_TASK_CREATED_RESOURCES_FILTER='(.components.schemas.TaskResponse|select(.)|.properties.created_resources.items) |= {"$oneOf":[{type:"null"},.]}'
68+
FIX_TASK_ERROR_FILTER='(.components.schemas.TaskResponse|select(.)|.properties.error) |= (del(.readOnly) | .additionalProperties.type = "string")'
69+
6470
if [ "$LANGUAGE" = "python" ]
6571
then
72+
cat "${API_SPEC}" | jq "." > patched-api.json
73+
6674
$CONTAINER_EXEC run \
6775
"${ULIMIT_COMMAND[@]}" \
6876
"${USER_COMMAND[@]}" \
6977
--rm \
7078
"${VOLUME_OPTION[@]}" \
7179
"$OPENAPI_PYTHON_IMAGE" generate \
72-
-i "${VOLUME_DIR}/${API_SPEC}" \
80+
-i "${VOLUME_DIR}/patched-api.json" \
7381
-g python \
7482
-o "${VOLUME_DIR}/${PACKAGE}-client" \
7583
"--additional-properties=packageName=pulpcore.client.${PACKAGE},projectName=${PACKAGE}-client,packageVersion=${VERSION},domainEnabled=${DOMAIN_ENABLED}" \
@@ -86,14 +94,15 @@ then
8694
mkdir -p "${PACKAGE}-client"
8795
echo git_push.sh > "${PACKAGE}-client/.openapi-generator-ignore"
8896

89-
python3 remove-cookie-auth.py
97+
cat "${API_SPEC}" | jq "${REMOVE_COOKIE_AUTH_FILTER}" > patched-api.json
98+
9099
$CONTAINER_EXEC run \
91100
"${ULIMIT_COMMAND[@]}" \
92101
"${USER_COMMAND[@]}" \
93102
--rm \
94103
"${VOLUME_OPTION[@]}" \
95104
"$OPENAPI_RUBY_IMAGE" generate \
96-
-i "${VOLUME_DIR}/${API_SPEC}" \
105+
-i "${VOLUME_DIR}/patched-api.json" \
97106
-g ruby \
98107
-o "${VOLUME_DIR}/${PACKAGE}-client" \
99108
"--additional-properties=gemName=${PACKAGE}_client,gemLicense="GPLv2+",gemVersion=${VERSION},gemHomepage=https://github.com/pulp/${PACKAGE}" \
@@ -105,13 +114,15 @@ fi
105114

106115
if [ "$LANGUAGE" = "typescript" ]
107116
then
117+
cat "${API_SPEC}" | jq "." > patched-api.json
118+
108119
$CONTAINER_EXEC run \
109120
"${ULIMIT_COMMAND[@]}" \
110121
"${USER_COMMAND[@]}" \
111122
--rm \
112123
"${VOLUME_OPTION[@]}" \
113124
"$OPENAPI_TYPESCRIPT_IMAGE" generate \
114-
-i "${VOLUME_DIR}/${API_SPEC}" \
125+
-i "${VOLUME_DIR}/patched-api.json" \
115126
-g typescript-axios \
116127
-o "${VOLUME_DIR}/${PACKAGE}-client" \
117128
-t "${VOLUME_DIR}/templates/typescript-axios" \

remove-cookie-auth.py

-58
This file was deleted.

0 commit comments

Comments
 (0)