Use all resource names for path param naming

for the url `/users/{user_id}/access_rules` and
`/users/{user_id}/access_rules/{id}` param user_id should be named as
`users_access_rules_user_id` to better avoid name shadowing.

Change-Id: Ibe72515cad25009fe5e73afe1a98dc07ec1ac8d4
This commit is contained in:
Artem Goncharov 2024-09-17 11:27:12 +02:00
parent a3da9ae657
commit f94c527051
2 changed files with 7 additions and 6 deletions

View File

@ -201,6 +201,9 @@ class KeystoneGenerator(OpenStackServerSourceBase):
path_params: list[ParameterSchema] = []
path_resource_names: list[str] = []
operation_tags = self._get_tags_for_url(path)
for path_element in path_elements:
if "{" not in path_element:
path_resource_names.append(path_element.replace("-", "_"))
for path_element in path_elements:
if "{" in path_element:
param_name = path_element.strip("{}")
@ -244,8 +247,6 @@ class KeystoneGenerator(OpenStackServerSourceBase):
openapi_spec.components.parameters[global_param_name] = (
path_param
)
else:
path_resource_names.append(path_element.replace("-", "_"))
if len(path_elements) == 0:
path_resource_names.append("root")
elif path_elements[-1].startswith("{"):

View File

@ -389,13 +389,13 @@ Some({{ val }})
// {{ res_name }}_id is passed. No need to lookup
{{ builder }}.{{ v.remote_name }}(id);
}
else if let Some(name) = &self.path.user.user_name {
else if let Some(name) = &self.path.{{ res_name }}.{{ res_name }}_name {
// {{ res_name }}_name is passed. Need to lookup resource
let mut find_builder = find_{{ res_name }}::Request::builder();
let mut sub_find_builder = find_{{ res_name }}::Request::builder();
warn!("Querying {{ res_name}} by name (because of `--{{res_name}}-name` parameter passed) may not be definite. This may fail in which case parameter `--{{res_name}}-id` should be used instead.");
find_builder.id(name);
let find_ep = find_builder
sub_find_builder.id(name);
let find_ep = sub_find_builder
.build()
.map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
let find_data: serde_json::Value = find_by_name(find_ep).query_async(client).await?;