From 01b6fefc9306fa911619a763ec9f947208e744a2 Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Fri, 12 Feb 2021 13:11:55 +0100 Subject: [PATCH] Simplify build for Python --- Dockerfile | 19 +++++++++++++++++++ Makefile | 11 +++++++++++ src/generators/python/index.ts | 14 +++++++++----- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c53c6ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:14 +RUN apt-get update && apt-get install -y default-jre \ + build-essential checkinstall libreadline-gplv2-dev \ + libncursesw5-dev libssl-dev libsqlite3-dev tk-dev \ + libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev \ + cd /opt && \ + wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tgz && \ + tar xzf Python-3.8.7.tgz && \ + cd /opt/Python-3.8.7 && \ + ./configure --enable-optimizations && \ + make altinstall && \ + rm -r /opt/Python-3.8.7 \ + rm /usr/bin/python && \ + ls -lah /usr/bin/python* && \ + ln -s $(which python3.8) /usr/bin/python +# TODO: make golang works +ENTRYPOINT ["/bin/bash", "-c"] +WORKDIR /src +CMD ["yarn start ts && yarn start python"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..25ec6b2 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +IMAGE_NAME?=h1-generators +IMAGE_TAG?=latest + +.PHONY: build +build: + wget -O openapi.json https://api.hyperone.com/v2/openapi.json + docker build -t ${IMAGE_NAME}:${IMAGE_TAG} . + +.PHONY: start +start: + docker run -v $$HOME/.h1/passport.json:/root/.h1/passport.json -v $$PWD:/src --workdir /src ${IMAGE_NAME}:${IMAGE_TAG} "${EXEC}" \ No newline at end of file diff --git a/src/generators/python/index.ts b/src/generators/python/index.ts index ca8e2f5..baabb32 100644 --- a/src/generators/python/index.ts +++ b/src/generators/python/index.ts @@ -5,13 +5,17 @@ import { execute } from "../../utils/shellUtils"; import { copyLicense } from "../../utils/licenseUtils"; import { fixPathsInReplacedReadme } from "../../utils/fileUtils"; -const dropObjectPattern = (s: any) => { + +const simplifyPattern = (value: string) => { + if(value) value = value.replace(/\?\<.+?\>/, '') +} +const simplifyObjectPattern = (s: any) => { if (!s.properties) return; for (const property of Object.values(s.properties)) { const p: any = property; - delete p.pattern; + p.pattern = simplifyPattern(p.pattern); if (p.items) { - dropObjectPattern(p.items) + simplifyObjectPattern(p.items) } } } @@ -29,7 +33,7 @@ export const generatePythonClient = async ( // example value: '.components.schemas.iam_project_policy_create.properties.resource' for (const schema of Object.values(specification.components.schemas)) { const s: any = schema; - dropObjectPattern(s); + simplifyObjectPattern(s); } // example value: .paths["/iam/project/{projectId}/policy"].get.parameters for (const endpoint of Object.values(specification.paths)) { @@ -40,7 +44,7 @@ export const generatePythonClient = async ( for (const parameter of o.parameters) { const p: any = parameter; if (!p.schema) continue; - delete p.schema.pattern; + p.schema.pattern = simplifyPattern(p.pattern); } } }