From c8cf16b5e23890675b7975c0752deee9eefba39d Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Fri, 4 Oct 2024 15:18:10 +0200 Subject: [PATCH] remove zone_id QP from listing zone recordsets Currently codegenerator is not supporting param with the same name to be present in path and query params (and this makes no sense). In the DNS it was the case so get rid of it. Change-Id: Id1e619c9cea0b1c76d1da3cfcf20e547f3cd4b3f --- codegenerator/common/rust.py | 4 ++++ codegenerator/openapi/designate_schemas.py | 26 ++++++++++++++++------ codegenerator/templates/rust_macros.j2 | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/codegenerator/common/rust.py b/codegenerator/common/rust.py index 78e782d..165f897 100644 --- a/codegenerator/common/rust.py +++ b/codegenerator/common/rust.py @@ -1029,6 +1029,10 @@ class TypeManager: is_flag=parameter.is_flag, resource_link=parameter.resource_link, ) + if param.local_name in self.parameters: + raise RuntimeError( + "Parameter with the name {param.local_name} is already present" + ) self.parameters[param.local_name] = param def get_parameters( diff --git a/codegenerator/openapi/designate_schemas.py b/codegenerator/openapi/designate_schemas.py index 61da7ad..a481c59 100644 --- a/codegenerator/openapi/designate_schemas.py +++ b/codegenerator/openapi/designate_schemas.py @@ -367,7 +367,7 @@ RECORDSETS_SCHEMA: dict[str, Any] = { "additionalProperties": False, } -RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { +ZONE_RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { "x-auth-all-projects": { "in": "header", "name": "x-auth-all-projects", @@ -418,12 +418,6 @@ RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { ], }, }, - "zone_id": { - "in": "query", - "name": "zone_id", - "description": "ID of the zone", - "schema": {"type": "string", "format": "uuid"}, - }, "name": { "in": "query", "name": "name", @@ -462,6 +456,16 @@ RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { }, } +RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { + "zone_id": { + "in": "query", + "name": "zone_id", + "description": "ID for the zone", + "schema": {"type": "string", "format": "uuid"}, + }, + **ZONE_RECORDSETS_LIST_PARAMETERS, +} + def _post_process_operation_hook( openapi_spec, operation_spec, path: str | None = None @@ -477,6 +481,14 @@ def _post_process_operation_hook( if ref not in [x.ref for x in operation_spec.parameters]: operation_spec.parameters.append(ParameterSchema(ref=ref)) elif operationId == "zones/zone_id/recordsets:get": + for key, val in ZONE_RECORDSETS_LIST_PARAMETERS.items(): + openapi_spec.components.parameters.setdefault( + key, ParameterSchema(**val) + ) + ref = f"#/components/parameters/{key}" + if ref not in [x.ref for x in operation_spec.parameters]: + operation_spec.parameters.append(ParameterSchema(ref=ref)) + elif operationId == "recordsets:get": for key, val in RECORDSETS_LIST_PARAMETERS.items(): openapi_spec.components.parameters.setdefault( key, ParameterSchema(**val) diff --git a/codegenerator/templates/rust_macros.j2 b/codegenerator/templates/rust_macros.j2 index 4ec3849..f184da4 100644 --- a/codegenerator/templates/rust_macros.j2 +++ b/codegenerator/templates/rust_macros.j2 @@ -462,7 +462,7 @@ Some({{ val }}) "{{ prefix }}{{ url }}", {%- for k, v in params.items() %} {%- if v.location == "path" %} - {{ k }} = {{ ('"' + k + '"') if not from_attr else ('self.' + v.local_name + '.as_ref()') }}, + {{ v.local_name }} = {{ ('"' + v.local_name + '"') if not from_attr else ('self.' + v.local_name + '.as_ref()') }}, {%- endif %} {%- endfor %} )