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 %} )