Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from gtema/dev
Browse files Browse the repository at this point in the history
feat: use api ver in openapi file name
  • Loading branch information
gtema authored Mar 6, 2024
2 parents e87f6c3 + e6481b6 commit 6b63ea8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
12 changes: 10 additions & 2 deletions codegenerator/openapi/cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def generate(self, target_dir, args):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Cinder OpenAPI schma")
return Path(target_dir, "openapi_specs", "block-storage", "v3.yaml")

def _generate(self, target_dir, args, *pargs, **kwargs):
from cinder import objects, rpc
Expand Down Expand Up @@ -73,7 +72,12 @@ def _generate(self, target_dir, args, *pargs, **kwargs):
work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(work_dir, "openapi_specs", "block-storage", "v3.yaml")
impl_path = Path(
work_dir,
"openapi_specs",
"block-storage",
f"v{self.api_version}.yaml",
)
impl_path.parent.mkdir(parents=True, exist_ok=True)

openapi_spec = self.load_openapi(impl_path)
Expand Down Expand Up @@ -120,6 +124,10 @@ def _generate(self, target_dir, args, *pargs, **kwargs):

self.dump_openapi(openapi_spec, impl_path, args.validate)

lnk = Path(impl_path.parent, "v3.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path

def _post_process_operation_hook(
Expand Down
8 changes: 7 additions & 1 deletion codegenerator/openapi/glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ def _generate(self, target_dir, args):
work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(work_dir, "openapi_specs", "image", "v2.yaml")
impl_path = Path(
work_dir, "openapi_specs", "image", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)

openapi_spec = self.load_openapi(impl_path)
Expand Down Expand Up @@ -321,6 +323,10 @@ def _generate(self, target_dir, args):

self.dump_openapi(openapi_spec, impl_path, args.validate)

lnk = Path(impl_path.parent, "v2.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path

def _post_process_operation_hook(
Expand Down
11 changes: 9 additions & 2 deletions codegenerator/openapi/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ def generate(self, target_dir, args):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Keystone OpenAPI schema")
return Path(target_dir, "openapi_specs", "identity", "v3.yaml")

def _generate(self, target_dir, args, *pargs, **kwargs):
from keystone.server.flask import application
from keystone import version as keystone_version

self.app = application.application_factory()
self.router = self.app.url_map
self.api_version = keystone_version.release_string()[1:]

work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(work_dir, "openapi_specs", "identity", "v3.yaml")
impl_path = Path(
work_dir, "openapi_specs", "identity", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)

openapi_spec = self.load_openapi(impl_path)
Expand Down Expand Up @@ -161,6 +164,10 @@ def _generate(self, target_dir, args, *pargs, **kwargs):

self.dump_openapi(openapi_spec, impl_path, args.validate)

lnk = Path(impl_path.parent, "v3.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path

def _process_route(self, route, openapi_spec):
Expand Down
7 changes: 6 additions & 1 deletion codegenerator/openapi/keystone_schemas/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@
}

MAPPING_PROPERTIES = replace_refs(
federation_mapping_schema.MAPPING_SCHEMA, proxies=False
(
federation_mapping_schema.IDP_ATTRIBUTE_MAPPING_SCHEMA_1_0
if hasattr(federation_mapping_schema, "IDP_ATTRIBUTE_MAPPING_SCHEMA")
else federation_mapping_schema.MAPPING_SCHEMA
),
proxies=False,
)
MAPPING_PROPERTIES.pop("definitions", None)
MAPPING_SCHEMA: dict[str, Any] = {
Expand Down
12 changes: 11 additions & 1 deletion codegenerator/openapi/neutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ def process_neutron_with_vpnaas(self, work_dir, processed_routes, args):

def _read_spec(self, work_dir):
"""Read the spec from file or create an empty one"""
impl_path = Path(work_dir, "openapi_specs", "network", "v2.yaml")
from neutron import version as neutron_version

nv = neutron_version.version_info.semantic_version().version_tuple()
self.api_version = f"2.{nv[0]}"
impl_path = Path(
work_dir, "openapi_specs", "network", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)
openapi_spec = self.load_openapi(Path(impl_path))
if not openapi_spec:
Expand Down Expand Up @@ -278,6 +284,10 @@ def _read_spec(self, work_dir):
schemas={},
),
)
lnk = Path(impl_path.parent, "v2.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return (impl_path, openapi_spec)

def generate(self, target_dir, args):
Expand Down
9 changes: 7 additions & 2 deletions codegenerator/openapi/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _generate(self, target_dir, args):
work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(work_dir, "openapi_specs", "compute", "v2.yaml")
impl_path = Path(
work_dir, "openapi_specs", "compute", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)

openapi_spec = self.load_openapi(impl_path)
Expand Down Expand Up @@ -103,6 +105,10 @@ def _generate(self, target_dir, args):

self.dump_openapi(openapi_spec, impl_path, args.validate)

lnk = Path(impl_path.parent, "v2.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path

def generate(self, target_dir, args):
Expand All @@ -111,7 +117,6 @@ def generate(self, target_dir, args):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Compute OpenAPI schema")
return Path(target_dir, "openapi_specs", "compute", "v2.yaml")

def _get_param_ref(
self,
Expand Down
10 changes: 8 additions & 2 deletions codegenerator/openapi/octavia.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def generate(self, target_dir, args):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Octavia OpenAPI schma")
return Path(target_dir, "openapi_specs", "load-balancing", "v2.yaml")

def _generate(self, target_dir, args):
from octavia.api import root_controller
Expand All @@ -171,7 +170,10 @@ def _generate(self, target_dir, args):
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(
work_dir, "openapi_specs", "load-balancing", "v2.yaml"
work_dir,
"openapi_specs",
"load-balancing",
f"v{self.api_version}.yaml",
)
impl_path.parent.mkdir(parents=True, exist_ok=True)
openapi_spec = self.load_openapi(Path(impl_path))
Expand Down Expand Up @@ -389,4 +391,8 @@ def _generate(self, target_dir, args):

self.dump_openapi(openapi_spec, Path(impl_path), args.validate)

lnk = Path(impl_path.parent, "v2.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path
9 changes: 7 additions & 2 deletions codegenerator/openapi/placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def _generate(self, target_dir, args):
work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)

impl_path = Path(work_dir, "openapi_specs", "placement", "v1.yaml")
impl_path = Path(
work_dir, "openapi_specs", "placement", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)

openapi_spec = self.load_openapi(impl_path)
Expand Down Expand Up @@ -97,6 +99,10 @@ def _generate(self, target_dir, args):

self.dump_openapi(openapi_spec, impl_path, args.validate)

lnk = Path(impl_path.parent, "v1.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)

return impl_path

def generate(self, target_dir, args):
Expand All @@ -105,4 +111,3 @@ def generate(self, target_dir, args):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Placement OpenAPI schema")
return Path(target_dir, "openapi_specs", "placement", "v2.yaml")

0 comments on commit 6b63ea8

Please sign in to comment.