feat: introduce openapi-generator (#95)
* move files related to swagger-codegen to dedicated directory * add script to build clients by openapi-generator * python-asyncio is build by openapi-generator
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
e41b173d3e
commit
d0821e65aa
@@ -46,7 +46,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
# this is to ensure sed after docker build has perm to modify files generated
|
||||
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-v2.3.0}"; \
|
||||
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
# Latest version of HaskellHttpClientCodegen.java as of Nov 19, 2018
|
||||
|
||||
@@ -46,7 +46,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-5d263e1c9cdd395d93adf061c63d5ef58a8e9ec5}"; \
|
||||
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-5d263e1c9cdd395d93adf061c63d5ef58a8e9ec5}"; \
|
||||
|
||||
66
openapi/openapi-generator/Dockerfile
Normal file
66
openapi/openapi-generator/Dockerfile
Normal file
@@ -0,0 +1,66 @@
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FROM maven:3.5-jdk-8-slim
|
||||
ARG OPENAPI_GENERATOR_COMMIT
|
||||
ARG GENERATION_XML_FILE
|
||||
ARG OPENAPI_GENERATOR_USER_ORG=OpenAPITools
|
||||
|
||||
# Install preprocessing script requirements
|
||||
RUN apt-get update && apt-get -y install git python-pip && pip install urllib3
|
||||
|
||||
# Install Autorest
|
||||
RUN apt-get update && apt-get -qq -y install libunwind8 libicu57 libssl1.0 liblttng-ust0 libcurl3 libuuid1 libkrb5-3 zlib1g
|
||||
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
|
||||
RUN apt-get update && apt-get -y install \
|
||||
nodejs \
|
||||
libunwind8-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN npm install -g autorest
|
||||
|
||||
# Check out specific commit of openapi-generator
|
||||
RUN mkdir /source && \
|
||||
cd /source && \
|
||||
git clone -n https://github.com/${OPENAPI_GENERATOR_USER_ORG}/openapi-generator.git && \
|
||||
cd openapi-generator && \
|
||||
git checkout $OPENAPI_GENERATOR_COMMIT
|
||||
|
||||
# Build it and persist local repository
|
||||
RUN mkdir /.npm && chmod -R go+rwx /.npm && chmod -R go+rwx /root && umask 0 && cd /source/openapi-generator && \
|
||||
mvn install -DskipTests -Dmaven.test.skip=true -pl modules/openapi-generator-maven-plugin -am && \
|
||||
cp -r /root/.m2/* /usr/share/maven/ref
|
||||
|
||||
RUN mkdir -p /node_modules && chmod -R go+rwx /node_modules
|
||||
RUN npm install @microsoft.azure/autorest.csharp \
|
||||
@microsoft.azure/autorest.modeler
|
||||
|
||||
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
|
||||
RUN mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
|
||||
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > prod.list
|
||||
RUN mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
|
||||
RUN chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
|
||||
RUN chown root:root /etc/apt/sources.list.d/microsoft-prod.list
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy -q dotnet-hosting-2.0.8
|
||||
|
||||
|
||||
# Copy required files
|
||||
COPY openapi-generator/generate_client_in_container.sh /generate_client.sh
|
||||
COPY preprocess_spec.py /
|
||||
COPY custom_objects_spec.json /
|
||||
COPY ${GENERATION_XML_FILE} /generation_params.xml
|
||||
|
||||
ENTRYPOINT ["mvn-entrypoint.sh", "/generate_client.sh"]
|
||||
90
openapi/openapi-generator/client-generator.sh
Executable file
90
openapi/openapi-generator/client-generator.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2015 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Script to fetch latest swagger spec.
|
||||
# Puts the updated spec at api/swagger-spec/
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# Generates client.
|
||||
# Required env vars:
|
||||
# CLEANUP_DIRS: List of directories to cleanup before generation for this language
|
||||
# KUBERNETES_BRANCH: Kubernetes branch name to get the swagger spec from
|
||||
# CLIENT_VERSION: Client version. Will be used in the comment sections of the generated code
|
||||
# PACKAGE_NAME: Name of the client package.
|
||||
# CLIENT_LANGUAGE: Language of the client. ${CLIENT_LANGUAGE}.xml should exists.
|
||||
# Optional env vars:
|
||||
# OPENAPI_GENERATOR_USER_ORG: openapi-generator-user-org
|
||||
# OPENAPI_GENERATOR_COMMIT: openapi-generator-version
|
||||
# Input vars:
|
||||
# $1: output directory
|
||||
kubeclient::generator::generate_client() {
|
||||
: "${CLEANUP_DIRS?Must set CLEANUP_DIRS env var}"
|
||||
: "${KUBERNETES_BRANCH?Must set KUBERNETES_BRANCH env var}"
|
||||
: "${CLIENT_VERSION?Must set CLIENT_VERSION env var}"
|
||||
: "${PACKAGE_NAME?Must set PACKAGE_NAME env var}"
|
||||
: "${CLIENT_LANGUAGE?Must set CLIENT_LANGUAGE env var}"
|
||||
|
||||
OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG:-OpenAPITools}"
|
||||
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v3.3.4}"
|
||||
USERNAME="${USERNAME:-kubernetes}"
|
||||
REPOSITORY="${REPOSITORY:-kubernetes}"
|
||||
|
||||
local output_dir=$1
|
||||
pushd "${output_dir}" > /dev/null
|
||||
local output_dir=`pwd`
|
||||
popd > /dev/null
|
||||
local SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
pushd "${SCRIPT_ROOT}" > /dev/null
|
||||
local SCRIPT_ROOT=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
mkdir -p "${output_dir}"
|
||||
|
||||
if [ "${USERNAME}" != "kubernetes" ]; then
|
||||
image_name="${USERNAME}-${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen-with-openapi-generator:v1"
|
||||
else
|
||||
image_name="${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen-with-openapi-generator:v1"
|
||||
fi
|
||||
|
||||
echo "--- Building docker image ${image_name}..."
|
||||
docker build "${SCRIPT_ROOT}"/../ -f "${SCRIPT_ROOT}/Dockerfile" -t "${image_name}" \
|
||||
--build-arg OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG}" \
|
||||
--build-arg OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT}" \
|
||||
--build-arg GENERATION_XML_FILE="${CLIENT_LANGUAGE}.xml"
|
||||
|
||||
# Docker does not support passing arrays, pass the string representation
|
||||
# of the array instead (space separated)
|
||||
CLEANUP_DIRS_STRING="${CLEANUP_DIRS[@]}"
|
||||
|
||||
echo "--- Running generator inside container..."
|
||||
docker run -u $(id -u) \
|
||||
-e CLEANUP_DIRS="${CLEANUP_DIRS_STRING}" \
|
||||
-e KUBERNETES_BRANCH="${KUBERNETES_BRANCH}" \
|
||||
-e CLIENT_VERSION="${CLIENT_VERSION}" \
|
||||
-e CLIENT_LANGUAGE="${CLIENT_LANGUAGE}" \
|
||||
-e PACKAGE_NAME="${PACKAGE_NAME}" \
|
||||
-e OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG}" \
|
||||
-e OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT}" \
|
||||
-e USERNAME="${USERNAME}" \
|
||||
-e REPOSITORY="${REPOSITORY}" \
|
||||
-v "${output_dir}:/output_dir" \
|
||||
"${image_name}" "/output_dir"
|
||||
|
||||
echo "---Done."
|
||||
}
|
||||
103
openapi/openapi-generator/generate_client_in_container.sh
Executable file
103
openapi/openapi-generator/generate_client_in_container.sh
Executable file
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2017 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Script to fetch latest swagger spec.
|
||||
# Puts the updated spec at api/swagger-spec/
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# Generates client.
|
||||
# Required env vars:
|
||||
# CLEANUP_DIRS: List of directories (string separated by space) to cleanup before generation for this language
|
||||
# KUBERNETES_BRANCH: Kubernetes branch name to get the swagger spec from
|
||||
# CLIENT_VERSION: Client version. Will be used in the comment sections of the generated code
|
||||
# PACKAGE_NAME: Name of the client package.
|
||||
# OPENAPI_GENERATOR_COMMIT: openapi-generator commit sha or tag/branch name. Will only be used as a reference in docs.
|
||||
# Input vars:
|
||||
# $1: output directory
|
||||
: "${CLEANUP_DIRS?Must set CLEANUP_DIRS env var}"
|
||||
: "${KUBERNETES_BRANCH?Must set KUBERNETES_BRANCH env var}"
|
||||
: "${CLIENT_VERSION?Must set CLIENT_VERSION env var}"
|
||||
: "${CLIENT_LANGUAGE?Must set CLIENT_LANGUAGE env var}"
|
||||
: "${PACKAGE_NAME?Must set PACKAGE_NAME env var}"
|
||||
: "${OPENAPI_GENERATOR_COMMIT?Must set OPENAPI_GENERATOR_COMMIT env var}"
|
||||
|
||||
output_dir=$1
|
||||
pushd "${output_dir}" > /dev/null
|
||||
output_dir=`pwd`
|
||||
popd > /dev/null
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
pushd "${SCRIPT_ROOT}" > /dev/null
|
||||
SCRIPT_ROOT=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
if ! which mvn > /dev/null 2>&1; then
|
||||
echo "Maven is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
# There should be only one version of openapi-generator-maven-plugin.
|
||||
unset PLUGIN_VERSION
|
||||
shopt -s nullglob
|
||||
FOLDERS=(/root/.m2/repository/org/openapitools/openapi-generator-maven-plugin/*)
|
||||
for folder in "${FOLDERS[@]}"; do
|
||||
if [[ -d "${folder}" ]]; then
|
||||
folder=$(basename "${folder}")
|
||||
if [[ ! -z "${PLUGIN_VERSION:-}" ]]; then
|
||||
echo "Multiple openapi-generator-maven-plugin version exists: ${PLUGIN_VERSION} & ${folder}"
|
||||
exit 1
|
||||
fi
|
||||
PLUGIN_VERSION="${folder}"
|
||||
fi
|
||||
done
|
||||
if [[ -z "${PLUGIN_VERSION:-}" ]]; then
|
||||
echo "Cannot find openapi-generator-maven-plugin version"
|
||||
exit 1
|
||||
fi
|
||||
shopt -u nullglob
|
||||
|
||||
# To make sure we can reproduce generation, we would also log code-gen exact commit
|
||||
pushd /source/openapi-generator
|
||||
OPENAPI_GENERATOR_COMMIT_ACTUAL=$(git rev-parse HEAD)
|
||||
popd
|
||||
|
||||
mkdir -p "${output_dir}"
|
||||
|
||||
echo "--- Downloading and pre-processing OpenAPI spec"
|
||||
python "${SCRIPT_ROOT}/preprocess_spec.py" "${CLIENT_LANGUAGE}" "${KUBERNETES_BRANCH}" "${output_dir}/swagger.json" "${USERNAME}" "${REPOSITORY}"
|
||||
|
||||
echo "--- Cleaning up previously generated folders"
|
||||
for i in ${CLEANUP_DIRS}; do
|
||||
echo "--- Cleaning up ${output_dir}/${i}"
|
||||
rm -rf "${output_dir}/${i}"
|
||||
done
|
||||
|
||||
echo "--- Generating client ..."
|
||||
mvn -f "${SCRIPT_ROOT}/generation_params.xml" clean generate-sources \
|
||||
-Dgenerator.spec.path="${output_dir}/swagger.json" \
|
||||
-Dgenerator.output.path="${output_dir}" \
|
||||
-D=generator.client.version="${CLIENT_VERSION}" \
|
||||
-D=generator.package.name="${PACKAGE_NAME}" \
|
||||
-D=openapi-generator-version="${PLUGIN_VERSION}" \
|
||||
-Duser.home=/root
|
||||
|
||||
mkdir -p "${output_dir}/.openapi-generator"
|
||||
echo "Requested Commit: ${OPENAPI_GENERATOR_COMMIT}" > "${output_dir}/.openapi-generator/COMMIT"
|
||||
echo "Actual Commit: ${OPENAPI_GENERATOR_COMMIT_ACTUAL}" >> "${output_dir}/.openapi-generator/COMMIT"
|
||||
|
||||
echo "---Done."
|
||||
@@ -1,27 +0,0 @@
|
||||
61a62
|
||||
> _pool = None
|
||||
64c65
|
||||
< cookie=None):
|
||||
---
|
||||
> cookie=None, pool_threads=None):
|
||||
67a69
|
||||
> self.pool_threads = pool_threads
|
||||
69d70
|
||||
< self.pool = ThreadPool()
|
||||
79,80c80,92
|
||||
< self.pool.close()
|
||||
< self.pool.join()
|
||||
---
|
||||
> if self._pool:
|
||||
> self._pool.close()
|
||||
> self._pool.join()
|
||||
> self._pool = None
|
||||
>
|
||||
> @property
|
||||
> def pool(self):
|
||||
> """Create thread pool on first request
|
||||
> avoids instantiating unused threadpool for blocking clients.
|
||||
> """
|
||||
> if self._pool is None:
|
||||
> self._pool = ThreadPool(self.pool_threads)
|
||||
> return self._pool
|
||||
@@ -1,39 +0,0 @@
|
||||
21a22,23
|
||||
> import asyncio
|
||||
>
|
||||
64a67,70
|
||||
> if not configuration.verify_ssl:
|
||||
> ssl_context.check_hostname = False
|
||||
> ssl_context.verify_mode = ssl.CERT_NONE
|
||||
>
|
||||
67,68c73
|
||||
< ssl_context=ssl_context,
|
||||
< verify_ssl=configuration.verify_ssl
|
||||
---
|
||||
> ssl_context=ssl_context
|
||||
81a87,89
|
||||
> def __del__(self):
|
||||
> asyncio.ensure_future(self.pool_manager.close())
|
||||
>
|
||||
130a139,141
|
||||
> if headers['Content-Type'] == 'application/json-patch+json':
|
||||
> if not isinstance(body, list):
|
||||
> headers['Content-Type'] = 'application/strategic-merge-patch+json'
|
||||
164c175,177
|
||||
< async with self.pool_manager.request(**args) as r:
|
||||
---
|
||||
> r = await self.pool_manager.request(**args)
|
||||
> if _preload_content:
|
||||
>
|
||||
168,169c181,182
|
||||
< # log response body
|
||||
< logger.debug("response body: %s", r.data)
|
||||
---
|
||||
> # log response body
|
||||
> logger.debug("response body: %s", r.data)
|
||||
171,172c184,185
|
||||
< if not 200 <= r.status <= 299:
|
||||
< raise ApiException(http_resp=r)
|
||||
---
|
||||
> if not 200 <= r.status <= 299:
|
||||
> raise ApiException(http_resp=r)
|
||||
@@ -41,66 +41,52 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
# Client specific Swagger branch to use.
|
||||
if [ ${PACKAGE_NAME} == "client" ]; then
|
||||
SWAGGER_CODEGEN_COMMIT=f9b2839a3076f26db1b8fc61655a26662f2552ee
|
||||
else
|
||||
SWAGGER_CODEGEN_COMMIT=v2.3.1
|
||||
fi
|
||||
|
||||
# Build the client library in a Docker container.
|
||||
CLIENT_LANGUAGE=python-asyncio
|
||||
CLEANUP_DIRS=(client/apis client/models docs test)
|
||||
kubeclient::generator::generate_client "${OUTPUT_DIR}"
|
||||
# use openapi-generator to generate library
|
||||
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
|
||||
|
||||
# Generic patches to the generated Python code, most notably renaming the library.
|
||||
echo "--- Patching generated code..."
|
||||
CLIENT_LANGUAGE=python-asyncio
|
||||
CLEANUP_DIRS=(client/apis client/models docs test)
|
||||
kubeclient::generator::generate_client "${OUTPUT_DIR}"
|
||||
|
||||
# Post-processing of the generated Python wrapper.
|
||||
if [ ${PACKAGE_NAME} == "client" ]; then
|
||||
# Generic patches to the generated Python code, most notably renaming the library.
|
||||
echo "--- Patching generated code..."
|
||||
|
||||
# Post-processing of the generated Python wrapper.
|
||||
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i 's/\bclient/kubernetes_asyncio.client/g' {} +
|
||||
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/\bclient/kubernetes_asyncio.client/g' {} +
|
||||
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/kubernetes_asyncio.client-python/client-python/g' {} +
|
||||
|
||||
# workaround https://github.com/swagger-api/swagger-codegen/pull/7905
|
||||
# TODO: Remove this when above merges
|
||||
find "${OUTPUT_DIR}/client" -type f -name \*.py ! -name '__init__.py' -exec sed -i '/^from .*models.*/d' {} \;
|
||||
|
||||
# workaround https://github.com/swagger-api/swagger-codegen/pull/8204
|
||||
# + closing session
|
||||
# + support application/strategic-merge-patch+json
|
||||
# workaround https://github.com/swagger-api/swagger-codegen/pull/8797
|
||||
# + aiohttp without verify_ssl
|
||||
# TODO: Remove this when above merges
|
||||
patch "${OUTPUT_DIR}/client/rest.py" "${SCRIPT_ROOT}/python-asyncio-rest.py.patch"
|
||||
|
||||
# workaround https://github.com/swagger-api/swagger-codegen/pull/8401
|
||||
# TODO: Remove this when above merges
|
||||
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async=/async_req=/g' {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/async bool/async_req bool/g' {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i "s/'async'/'async_req'/g" {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i "s/async parameter/async_req parameter/g" {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i "s/if not async/if not async_req/g" {} +
|
||||
|
||||
# workaround https://github.com/swagger-api/swagger-codegen/pull/8061 (thread pool only on demand)
|
||||
# TODO: Remove this when above merges
|
||||
patch "${OUTPUT_DIR}/client/api_client.py" "${SCRIPT_ROOT}/python-asyncio-api_client.py.patch"
|
||||
|
||||
# fix imports
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_asyncio.client./g' {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes_asyncio.client/g' {} +
|
||||
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes_asyncio.client.models/g' {} +
|
||||
|
||||
else
|
||||
|
||||
# use swagger-codegen to generate library
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
|
||||
SWAGGER_CODEGEN_COMMIT=v2.3.1
|
||||
# Build the client library in a Docker container.
|
||||
CLIENT_LANGUAGE=python-asyncio
|
||||
CLEANUP_DIRS=(client/apis client/models docs test)
|
||||
kubeclient::generator::generate_client "${OUTPUT_DIR}"
|
||||
|
||||
# Generic patches to the generated Python code, most notably renaming the library.
|
||||
echo "--- Patching generated code..."
|
||||
|
||||
# Post-processing of the generated Python wrapper.
|
||||
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
|
||||
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
|
||||
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/${PACKAGE_NAME}.client-python/client-python/g" {} +
|
||||
|
||||
# Remove circular imports in `v1beta1_json_schema_props.py`.
|
||||
sed -i "/^from ${PACKAGE_NAME}\.models.*/d" "${PACKAGE_NAME}/${PACKAGE_NAME}/models/v1beta1_json_schema_props.py"
|
||||
|
||||
fi
|
||||
|
||||
echo "---Done."
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
<version>${swagger-codegen-version}</version>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -37,7 +37,7 @@
|
||||
<dependencies>
|
||||
<!-- dependencies are needed for the client being generated -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-d2b91073e1fc499fea67141ff4c17740d25f8e83}"; \
|
||||
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
CLIENT_LANGUAGE=ruby; \
|
||||
|
||||
@@ -58,7 +58,7 @@ RUN apt-get install -yy -q dotnet-hosting-2.0.8
|
||||
|
||||
|
||||
# Copy required files
|
||||
COPY generate_client_in_container.sh /generate_client.sh
|
||||
COPY swagger-codegen/generate_client_in_container.sh /generate_client.sh
|
||||
COPY preprocess_spec.py /
|
||||
COPY custom_objects_spec.json /
|
||||
COPY ${GENERATION_XML_FILE} /generation_params.xml
|
||||
@@ -49,20 +49,21 @@ kubeclient::generator::generate_client() {
|
||||
pushd "${output_dir}" > /dev/null
|
||||
local output_dir=`pwd`
|
||||
popd > /dev/null
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
local SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
pushd "${SCRIPT_ROOT}" > /dev/null
|
||||
local SCRIPT_ROOT=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
mkdir -p "${output_dir}"
|
||||
|
||||
echo "--- Building docker image..."
|
||||
if [ "${USERNAME}" != "kubernetes" ]; then
|
||||
image_name="${USERNAME}-${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen:v1"
|
||||
else
|
||||
image_name="${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen:v1"
|
||||
fi
|
||||
docker build "${SCRIPT_ROOT}" -t "${image_name}" \
|
||||
|
||||
echo "--- Building docker image ${image_name}..."
|
||||
docker build "${SCRIPT_ROOT}"/../ -f "${SCRIPT_ROOT}/Dockerfile" -t "${image_name}" \
|
||||
--build-arg SWAGGER_CODEGEN_USER_ORG="${SWAGGER_CODEGEN_USER_ORG}" \
|
||||
--build-arg SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT}" \
|
||||
--build-arg GENERATION_XML_FILE="${CLIENT_LANGUAGE}.xml"
|
||||
@@ -43,7 +43,7 @@ pushd "${OUTPUT_DIR}" > /dev/null
|
||||
OUTPUT_DIR=`pwd`
|
||||
popd > /dev/null
|
||||
|
||||
source "${SCRIPT_ROOT}/client-generator.sh"
|
||||
source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
|
||||
source "${SETTING_FILE}"
|
||||
|
||||
CLIENT_LANGUAGE=typescript; \
|
||||
|
||||
Reference in New Issue
Block a user