Skip to content

Commit 7c5706e

Browse files
committed
Fix build of Python
1 parent e65bd52 commit 7c5706e

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

src/generators/python/_README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ library installation description
2525
Then import it and use it as a token provider in your code:
2626

2727
```python
28-
from <credentials library name> import get_passport_credentials_helper
29-
from <client library name> import ApiClient, Configuration
28+
from credentials import get_passport_credentials_helper
29+
from h1 import ApiClient, Configuration
3030

3131
provider = get_passport_credentials_helper() # you can optionally pass passport file location
3232
cfg = Configuration()
@@ -42,8 +42,9 @@ Configuration object allows you to use choosen API client.
4242
Example:
4343

4444
```python
45-
from <credentials library name> import get_passport_credentials_helper
46-
from <client library name> import Configuration, ApiClient, IamProjectApi
45+
from credentials import get_passport_credentials_helper
46+
from h1 import Configuration, ApiClient
47+
from h1.api.iam_project_api import IamProjectApi
4748

4849
provider = get_passport_credentials_helper()
4950
cfg = Configuration()
@@ -73,7 +74,8 @@ api_client = ApiClient(cfg, header_name="prefer", header_value="respond-async,wa
7374
Full example:
7475

7576
```python
76-
from <client library name> import Configuration, ApiClient, IamProjectApi
77+
from h1 import Configuration, ApiClient
78+
from h1.api.iam_project_api import IamProjectApi
7779

7880
cfg = Configuration()
7981
api_client = ApiClient(cfg, header_name="prefer", header_value="respond-async,wait=86400")

src/generators/python/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
packageName: h1-client
2-
projectName: h1
1+
packageName: h1
2+
projectName: h1-client

src/generators/python/index.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
11
import { join } from "path";
2+
import { readFile, writeFile } from "fs/promises";
3+
24
import { execute } from "../../utils/shellUtils";
35
import { copyLicense } from "../../utils/licenseUtils";
46
import { fixPathsInReplacedReadme } from "../../utils/fileUtils";
57

8+
const dropObjectPattern = (s: any) => {
9+
if (!s.properties) return;
10+
for (const property of Object.values(s.properties)) {
11+
const p: any = property;
12+
delete p.pattern;
13+
if (p.items) {
14+
dropObjectPattern(p.items)
15+
}
16+
}
17+
}
18+
619
export const generatePythonClient = async (
720
openapiFile: string,
821
outputDir: string
922
): Promise<void> => {
1023
const config = join(__dirname, "config.yaml");
1124
const generator = "python";
12-
25+
const specification = JSON.parse(await readFile(openapiFile, {
26+
encoding: 'utf-8'
27+
}));
28+
// python does not pass validation our regexp
29+
// example value: '.components.schemas.iam_project_policy_create.properties.resource'
30+
for (const schema of Object.values(specification.components.schemas)) {
31+
const s: any = schema;
32+
dropObjectPattern(s);
33+
}
34+
// example value: .paths["/iam/project/{projectId}/policy"].get.parameters
35+
for (const endpoint of Object.values(specification.paths)) {
36+
const e: any = endpoint;
37+
for (const operation of Object.values(e)) {
38+
const o: any = operation;
39+
if (!o.parameters) continue;
40+
for (const parameter of o.parameters) {
41+
const p: any = parameter;
42+
if (!p.schema) continue;
43+
delete p.schema.pattern;
44+
}
45+
}
46+
}
47+
await writeFile(openapiFile, JSON.stringify(specification, null, 4));
1348
await execute(
1449
`yarn openapi-generator-cli generate --git-user-id "hyperonecom" --git-repo-id "h1-client-python" -i ${openapiFile} -c ${config} -g ${generator} -o ${outputDir}`
1550
);
@@ -32,7 +67,7 @@ export const generatePythonClient = async (
3267
const replacementReadmeLocation = join(__dirname, "_README.md");
3368
await execute(`cp ${replacementReadmeLocation} README.md`, outputDir);
3469

35-
await execute("pip install .", outputDir);
70+
await execute("python3.7 -m pip install .", outputDir);
3671

3772
await copyLicense("MIT", outputDir);
3873
};

tests/python/execute.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pip install -r ../../clients/python/requirements.txt
2-
pip install git+git://github.com/kuskoman/h1-credentials-helper-python.git
1+
#!/bin/sh
2+
set -eux
3+
python -m pip install -r ../../clients/python/requirements.txt
4+
python -m pip install git+git://github.com/hyperonecom/h1-credentials-helper-python.git
35

46
python test.py

tests/python/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from credentials import get_passport_credentials_helper
2-
from h1 import Configuration, ApiClient, IamProjectApi
3-
2+
from h1 import Configuration, ApiClient
3+
from h1.api.iam_project_api import IamProjectApi
44

55
def test_access_token_configuration():
66
provider = get_passport_credentials_helper()

0 commit comments

Comments
 (0)