python-fastapi-rest-server-codegen 1.7.6__py3-none-any.whl → 1.9.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,81 +1,81 @@
1
- import subprocess
2
- import os
3
- import lcdp_api.rest
4
- from pathlib import Path
5
-
6
- try:
7
- import importlib.resources as pkg_resources
8
- except ImportError:
9
- # Try backported to PY<37 `importlib_resources`.
10
- import importlib_resources as pkg_resources
11
-
12
- # Get current script dir
13
- CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
14
-
15
- # Codegen command constants
16
- OPENAPI_CODEGEN_CLASS = "org.openapitools.codegen.OpenAPIGenerator"
17
-
18
- def get_api_path(api_filename):
19
- return pkg_resources.path(lcdp_api.rest, api_filename)
20
-
21
- def get_codegen_cli_path():
22
- return pkg_resources.path(__package__, "openapi-generator-cli.jar")
23
-
24
- def get_codegen_path():
25
- return pkg_resources.path(__package__, "python-fastapi-rest-server-codegen.jar")
26
-
27
-
28
- def generate_provider(api_spec_file_name, out_dir):
29
- with get_api_path(api_spec_file_name) as api_spec_file_path:
30
- api_name = get_api_name_from_spec_file_path(api_spec_file_path)
31
-
32
- api_spec_file_abs_path = os.path.join(CURRENT_DIR, "..", api_spec_file_path)
33
-
34
- # Compute generator path
35
- with get_codegen_path() as server_codegen_jar_path, get_codegen_cli_path() as cli_jar_path:
36
- openapi_codegen_java_classpath = compute_codegen_java_classpath(cli_jar_path, server_codegen_jar_path)
37
-
38
- execute_provider_codegen(openapi_codegen_java_classpath, server_codegen_jar_path.stem, api_spec_file_abs_path,
39
- out_dir, "api.provide.gen", "api.provide.impl", api_name)
40
-
41
- def get_api_name_from_spec_file_path(api_spec_file_path):
42
- api_name = os.path.basename(api_spec_file_path).split(".")[0]
43
- return api_name.replace("-", "_")
44
-
45
-
46
- def compute_codegen_java_classpath(cli_jar_path, codegen_jar_path):
47
- sep = ";" if os.name == "nt" else ":"
48
- return sep.join([str(cli_jar_path), str(codegen_jar_path)])
49
-
50
-
51
- def execute_provider_codegen(openapi_codegen_java_classpath, codegen_name,
52
- api_spec_file_path, outdir,
53
- package_name, package_name_impl, api_name):
54
- """
55
- Provider is generated above leaf
56
- """
57
- properties = [
58
- "--package-name", package_name + "." + api_name
59
- ]
60
-
61
- additional_properties = [
62
- "controllerPackage=" + api_name + '.controllers',
63
- "packageNameImpl=" + package_name_impl + "." + api_name + ".controllers",
64
- "testPackage=" + api_name + '.tests',
65
- "apiDocPath=" + api_name + '/docs',
66
- "modelDocPath=" + api_name + '/docs',
67
- "fastapiImplementationPackage=" + package_name_impl + "." + api_name + ".controllers",
68
- "commonPackageName=" + package_name + ".common",
69
- ]
70
-
71
- execute_codegen_command(openapi_codegen_java_classpath, codegen_name, api_spec_file_path, outdir, properties,
72
- additional_properties)
73
-
74
- def execute_codegen_command(openapi_codegen_java_classpath, codegen_name, api_spec_file_path, outdir, properties,
75
- additional_properties):
76
- subprocess.check_call(["java", "-cp", openapi_codegen_java_classpath, OPENAPI_CODEGEN_CLASS, "generate", "-g",
77
- codegen_name, "-i", api_spec_file_path, "-o", outdir] +
78
- properties +
79
- # controllerPackage is used by server codegen
80
- ["--additional-properties=" + ",".join(additional_properties)
81
- ])
1
+ import subprocess
2
+ import os
3
+ import lcdp_api.rest
4
+ from pathlib import Path
5
+
6
+ try:
7
+ import importlib.resources as pkg_resources
8
+ except ImportError:
9
+ # Try backported to PY<37 `importlib_resources`.
10
+ import importlib_resources as pkg_resources
11
+
12
+ # Get current script dir
13
+ CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
14
+
15
+ # Codegen command constants
16
+ OPENAPI_CODEGEN_CLASS = "org.openapitools.codegen.OpenAPIGenerator"
17
+
18
+ def get_api_path(api_filename):
19
+ return pkg_resources.path(lcdp_api.rest, api_filename)
20
+
21
+ def get_codegen_cli_path():
22
+ return pkg_resources.path(__package__, "openapi-generator-cli.jar")
23
+
24
+ def get_codegen_path():
25
+ return pkg_resources.path(__package__, "python-fastapi-rest-server-codegen.jar")
26
+
27
+
28
+ def generate_provider(api_spec_file_name, out_dir):
29
+ with get_api_path(api_spec_file_name) as api_spec_file_path:
30
+ api_name = get_api_name_from_spec_file_path(api_spec_file_path)
31
+
32
+ api_spec_file_abs_path = os.path.join(CURRENT_DIR, "..", api_spec_file_path)
33
+
34
+ # Compute generator path
35
+ with get_codegen_path() as server_codegen_jar_path, get_codegen_cli_path() as cli_jar_path:
36
+ openapi_codegen_java_classpath = compute_codegen_java_classpath(cli_jar_path, server_codegen_jar_path)
37
+
38
+ execute_provider_codegen(openapi_codegen_java_classpath, server_codegen_jar_path.stem, api_spec_file_abs_path,
39
+ out_dir, "api.provide.gen", "api.provide.impl", api_name)
40
+
41
+ def get_api_name_from_spec_file_path(api_spec_file_path):
42
+ api_name = os.path.basename(api_spec_file_path).split(".")[0]
43
+ return api_name.replace("-", "_")
44
+
45
+
46
+ def compute_codegen_java_classpath(cli_jar_path, codegen_jar_path):
47
+ sep = ";" if os.name == "nt" else ":"
48
+ return sep.join([str(cli_jar_path), str(codegen_jar_path)])
49
+
50
+
51
+ def execute_provider_codegen(openapi_codegen_java_classpath, codegen_name,
52
+ api_spec_file_path, outdir,
53
+ package_name, package_name_impl, api_name):
54
+ """
55
+ Provider is generated above leaf
56
+ """
57
+ properties = [
58
+ "--package-name", package_name + "." + api_name
59
+ ]
60
+
61
+ additional_properties = [
62
+ "controllerPackage=" + api_name + '.controllers',
63
+ "packageNameImpl=" + package_name_impl + "." + api_name + ".controllers",
64
+ "testPackage=" + api_name + '.tests',
65
+ "apiDocPath=" + api_name + '/docs',
66
+ "modelDocPath=" + api_name + '/docs',
67
+ "fastapiImplementationPackage=" + package_name_impl + "." + api_name + ".controllers",
68
+ "commonPackageName=" + package_name + ".common",
69
+ ]
70
+
71
+ execute_codegen_command(openapi_codegen_java_classpath, codegen_name, api_spec_file_path, outdir, properties,
72
+ additional_properties)
73
+
74
+ def execute_codegen_command(openapi_codegen_java_classpath, codegen_name, api_spec_file_path, outdir, properties,
75
+ additional_properties):
76
+ subprocess.check_call(["java", "-cp", openapi_codegen_java_classpath, OPENAPI_CODEGEN_CLASS, "generate", "-g",
77
+ codegen_name, "-i", api_spec_file_path, "-o", outdir] +
78
+ properties +
79
+ # controllerPackage is used by server codegen
80
+ ["--additional-properties=" + ",".join(additional_properties)
81
+ ])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-fastapi-rest-server-codegen
3
- Version: 1.7.6
3
+ Version: 1.9.1
4
4
  Summary: Python rest server codegen for Le Comptoir Des Pharmacies
5
5
  Home-page: https://bitbucket.org/lecomptoirdespharmacies/lcdp-openapi-codegen
6
6
  Author: Le Comptoir Des Pharmacies
@@ -0,0 +1,9 @@
1
+ python_fastapi_rest_server_codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ python_fastapi_rest_server_codegen/codegen.py,sha256=i1vfy1Q309P70PMkbIu_5ygEkEMelC-6zcUztJDFbM4,3273
3
+ python_fastapi_rest_server_codegen/openapi-generator-cli.jar,sha256=0Yec9C2jH4z2HPaHmLjvJBivDGvZOlwYcOH_VD-7k2U,29755831
4
+ python_fastapi_rest_server_codegen/python-fastapi-rest-server-codegen-tests.jar,sha256=g67X0uBwWM0i80OJu-Vo2iLlG6UBeFnOYHn75FQt4GU,152376
5
+ python_fastapi_rest_server_codegen/python-fastapi-rest-server-codegen.jar,sha256=MSj9_cVRSvOzlCFxbKMrQpPNoYweqLk2zHbpUbKXQ3E,17038
6
+ python_fastapi_rest_server_codegen-1.9.1.dist-info/METADATA,sha256=q9ar9sP__GS2d-sMGrq3jsKeF8UkzxQ3PpO7AWvqCro,644
7
+ python_fastapi_rest_server_codegen-1.9.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
8
+ python_fastapi_rest_server_codegen-1.9.1.dist-info/top_level.txt,sha256=zZakr63ekEbSIi37MF7dDDT6Ki7s_wOlcYqWHx_UPuE,35
9
+ python_fastapi_rest_server_codegen-1.9.1.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- python_fastapi_rest_server_codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- python_fastapi_rest_server_codegen/codegen.py,sha256=td5C7sXO63JKOHg3TUcOh--lXWwBiggOFxRDoXAsWh8,3354
3
- python_fastapi_rest_server_codegen/openapi-generator-cli.jar,sha256=0Yec9C2jH4z2HPaHmLjvJBivDGvZOlwYcOH_VD-7k2U,29755831
4
- python_fastapi_rest_server_codegen/python-fastapi-rest-server-codegen-tests.jar,sha256=i4bvKMi0BjKTCR45ua6sFlPJaJ4dvcpD9NL5WpXMXjQ,152919
5
- python_fastapi_rest_server_codegen/python-fastapi-rest-server-codegen.jar,sha256=Q9OoA3AjOSkR4EuulgjA6Ii_zCPGKsY5Lmc-mqnCLaU,17075
6
- python_fastapi_rest_server_codegen-1.7.6.dist-info/METADATA,sha256=CoAW0U9pGQsZTsZtxXMeWpGQ5HhZyxrYv3-M0ocI9iA,644
7
- python_fastapi_rest_server_codegen-1.7.6.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
8
- python_fastapi_rest_server_codegen-1.7.6.dist-info/top_level.txt,sha256=zZakr63ekEbSIi37MF7dDDT6Ki7s_wOlcYqWHx_UPuE,35
9
- python_fastapi_rest_server_codegen-1.7.6.dist-info/RECORD,,