Skip to content

Simplify build for Python #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}"
14 changes: 9 additions & 5 deletions src/generators/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)) {
Expand All @@ -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);
}
}
}
Expand Down