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 #7 from gtema/identity
Browse files Browse the repository at this point in the history
feat: start generating identiy resources
  • Loading branch information
gtema authored Jan 16, 2024
2 parents 3860c68 + cfa196d commit 78ef63d
Show file tree
Hide file tree
Showing 13 changed files with 3,899 additions and 274 deletions.
2 changes: 2 additions & 0 deletions codegenerator/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def get_rust_service_type_from_str(xtype: str):
return "BlockStorage"
case "compute":
return "Compute"
case "identity":
return "Identity"
case "image":
return "Image"
case "network":
Expand Down
10 changes: 8 additions & 2 deletions codegenerator/common/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,9 @@ def get_operation_variants(spec: dict, operation_name: str):
logging.debug("Microversion discriminator for bodies")
for variant in json_body_schema["oneOf"]:
variant_spec = variant.get("x-openstack", {})
operation_variants.append({"body": variant})
operation_variants.append(
{"body": variant, "mime_type": mime_type}
)
# operation_variants.extend([{"body": x} for x in json_body_schema(["oneOf"])])
elif discriminator == "action":
# We are in the action. Need to find matching body
Expand All @@ -949,6 +951,7 @@ def get_operation_variants(spec: dict, operation_name: str):
"min-ver": subvariant_spec.get(
"min-ver"
),
"mime_type": mime_type,
}
)
else:
Expand All @@ -960,6 +963,7 @@ def get_operation_variants(spec: dict, operation_name: str):
"body": variant,
"mode": "action",
"min-ver": variant_spec.get("min-ver"),
"mime_type": mime_type,
}
)
break
Expand All @@ -969,7 +973,9 @@ def get_operation_variants(spec: dict, operation_name: str):
% operation_name
)
else:
operation_variants.append({"body": json_body_schema})
operation_variants.append(
{"body": json_body_schema, "mime_type": mime_type}
)
elif "application/octet-stream" in content:
mime_type = "application/octet-stream"
operation_variants.append({"mime_type": mime_type})
Expand Down
38 changes: 35 additions & 3 deletions codegenerator/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,18 @@ def generate(
if path.endswith("}"):
if method == "get":
operation_key = "show"
elif method == "head":
operation_key = "check"
elif method == "put":
operation_key = "update"
elif method == "patch":
operation_key = "patch"
if (
"application/json"
in operation.requestBody.get("content", {})
):
operation_key = "update"
else:
operation_key = "patch"
elif method == "post":
operation_key = "create"
elif method == "delete":
Expand Down Expand Up @@ -170,20 +178,37 @@ def generate(
# level
if method == "get":
operation_key = "list"
elif method == "head":
operation_key = "check"
elif method == "patch":
if (
"application/json"
in operation.requestBody.get("content", {})
):
operation_key = "update"
else:
operation_key = "patch"
elif method == "post":
operation_key = "create"
elif method == "put":
operation_key = "replace"
elif method == "delete":
operation_key = "delete_all"
elif method == "head":
operation_key = "check"
elif method == "get":
operation_key = "get"
elif method == "post":
operation_key = "create"
elif method == "put":
operation_key = path.split("/")[-1]
elif method == "patch":
operation_key = "patch"
if "application/json" in operation.requestBody.get(
"content", {}
):
operation_key = "update"
else:
operation_key = "patch"
elif method == "delete":
operation_key = "delete"
if not operation_key:
Expand Down Expand Up @@ -321,7 +346,10 @@ def generate(
rust_cli_params.operation_type = "json"

op_model.targets["rust-sdk"] = rust_sdk_params
if rust_cli_params:
if rust_cli_params and not (
args.service_type == "identity"
and operation_key == "check"
):
op_model.targets["rust-cli"] = rust_cli_params
resource_model.operations[operation_key] = op_model
pass
Expand Down Expand Up @@ -439,6 +467,8 @@ def get_operation_type_by_key(operation_key):
return "list"
elif operation_key == "get":
return "get"
elif operation_key == "check":
return "get"
elif operation_key == "show":
return "show"
elif operation_key in ["update", "replace"]:
Expand Down Expand Up @@ -509,6 +539,8 @@ def get_module_name(name):
return "get"
elif name == "show":
return "show"
elif name == "check":
return "head"
elif name == "update":
return "set"
elif name == "replace":
Expand Down
Loading

0 comments on commit 78ef63d

Please sign in to comment.