diff --git a/codegenerator/metadata.py b/codegenerator/metadata.py index 4bf3cbc..781b2f8 100644 --- a/codegenerator/metadata.py +++ b/codegenerator/metadata.py @@ -413,6 +413,11 @@ class MetadataGenerator(BaseGenerator): operation_key = "abandon" if path == "/v2/zones/{zone_id}/tasks/pool_move": operation_key = "pool_move" + elif resource_name == "quota" and path == "/v2/quotas": + # /quotas return quota for current project and not + # a "list" for all projects. As such it has no + # difference to show + continue if operation_key in resource_model: raise RuntimeError("Operation name conflict") diff --git a/codegenerator/openapi/base.py b/codegenerator/openapi/base.py index e74958a..c2e9cbc 100644 --- a/codegenerator/openapi/base.py +++ b/codegenerator/openapi/base.py @@ -1079,7 +1079,7 @@ class OpenStackServerSourceBase: param_location: str, path: str | None = None, **param_attrs, - ): + ) -> str: if ref_name == "_project_id": ref_name = "project_id" ref_name = ref_name.replace(":", "_") diff --git a/codegenerator/openapi/designate.py b/codegenerator/openapi/designate.py index 13b2e9b..69e88a6 100644 --- a/codegenerator/openapi/designate.py +++ b/codegenerator/openapi/designate.py @@ -289,3 +289,30 @@ class DesignateGenerator(OpenStackServerSourceBase): action_name=action_name, ) return (ref, mime_type) + + def _get_param_ref( + self, + openapi_spec, + ref_name: str, + param_name: str, + param_location: str, + path: str | None = None, + **param_attrs, + ) -> str: + ref = super()._get_param_ref( + openapi_spec, + ref_name, + param_name, + param_location, + path, + **param_attrs, + ) + if ( + param_name == "zone_id" + and param_location == "path" + and ref_name != "zones_zone_id" + ): + openapi_spec.components.parameters[ref_name].openstack = { + "resource_link": "dns/v2/zone.id" + } + return ref diff --git a/codegenerator/openapi/designate_schemas.py b/codegenerator/openapi/designate_schemas.py index a481c59..240fc61 100644 --- a/codegenerator/openapi/designate_schemas.py +++ b/codegenerator/openapi/designate_schemas.py @@ -54,6 +54,9 @@ RECORDSET_STATUSES: list[str] = [ "SUCCESS", ] +PTR_ACTIONS: list[str] = ["UPDATE", "DELETE", "NONE"] +PTR_STATUSES: list[str] = ["ACTIVE", "PENDING", "DELETED", "ERROR", "SUCCESS"] + ZONE_SCHEMA: dict[str, Any] = { "type": "object", "description": "DNS Zone", @@ -156,6 +159,11 @@ ZONE_SCHEMA: dict[str, Any] = { "description": "True if the zone is shared with another project.", "x-openstack": {"min-ver": "2.1"}, }, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, }, "additionalProperties": False, } @@ -163,10 +171,108 @@ ZONE_SCHEMA: dict[str, Any] = { ZONES_SCHEMA: dict[str, Any] = { "type": "object", - "properties": {"zones": {"type": "array", "items": ZONE_SCHEMA}}, + "properties": { + "zones": {"type": "array", "items": ZONE_SCHEMA}, + "links": { + "type": "object", + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + }, "additionalProperties": False, } +ZONE_SHARE_SCHEMA: dict[str, Any] = { + "type": "object", + "description": "Shared DNS Zone", + "properties": { + "id": { + "type": "string", + "format": "uuid", + "readOnly": True, + "description": "ID for the resource", + }, + "project_id": { + "type": "string", + "format": "uuid", + "readOnly": True, + "description": "ID for the project that owns the resource", + }, + "target_project_id": { + "type": "string", + "format": "uuid", + "description": "The project ID the zone will be shared with.", + }, + "created_at": { + "type": "string", + "format": "date-time", + "readOnly": True, + "description": "Date / Time when resource was created.", + }, + "updated_at": { + "type": ["string", "null"], + "format": "date-time", + "readOnly": True, + "description": "Date / Time when resource last updated.", + }, + "links": { + "type": "object", + "readOnly": True, + "properties": { + "self": {"type": "string", "format": "uri"}, + "zone": {"type": "string", "format": "uri"}, + }, + }, + }, + "additionalProperties": False, +} + +ZONE_SHARES_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "shared_zones": {"type": "array", "items": ZONE_SHARE_SCHEMA}, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + }, + "additionalProperties": False, +} + +ZONE_SHARES_LIST_PARAMETERS: dict[str, Any] = { + "x-auth-all-projects": { + "in": "header", + "name": "x-auth-all-projects", + "description": "If enabled this will show results from all projects in Designate", + "schema": {"type": "bool"}, + }, + "x-auth-sudo-project-id": { + "in": "header", + "name": "x-auth-sudo-project-id", + "description": "This allows a user to impersonate another project", + "schema": {"type": "string"}, + }, + "limit": { + "in": "query", + "name": "limit", + "description": "Requests a page size of items. Returns a number of items up to a limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.", + "schema": {"type": "integer"}, + }, + "marker": { + "in": "query", + "name": "market", + "description": "The ID of the last-seen item. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.", + "schema": {"type": "string", "format": "uuid"}, + }, + "target_project_id": { + "in": "query", + "name": "target_project_id", + "description": "Filter results to only show resources that have a matching target_project_id", + "schema": {"type": "string", "format": "uuid"}, + "x-openstack": {"min-ver": "2.1"}, + }, +} + ZONES_LIST_PARAMETERS: dict[str, Any] = { "x-auth-all-projects": { "in": "header", @@ -269,6 +375,15 @@ NAMESERVER_SCHEMA: dict[str, Any] = { "readOnly": True, "description": "The priority of the nameserver. This is used to determine the order of the the nameserver listings, and which server is used in the SOA record for the zone.", }, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + "links": { + "type": "object", + "properties": {"self": {"type": "string", "format": "uri"}}, + }, }, "additionalProperties": False, } @@ -276,7 +391,12 @@ NAMESERVER_SCHEMA: dict[str, Any] = { NAMESERVERS_SCHEMA: dict[str, Any] = { "type": "object", "properties": { - "nameservers": {"type": "array", "items": NAMESERVER_SCHEMA} + "nameservers": {"type": "array", "items": NAMESERVER_SCHEMA}, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, }, "additionalProperties": False, } @@ -356,6 +476,11 @@ RECORDSET_SCHEMA: dict[str, Any] = { "readOnly": True, "description": "Date / Time when resource last updated.", }, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, }, "additionalProperties": False, } @@ -363,7 +488,18 @@ RECORDSET_SCHEMA: dict[str, Any] = { RECORDSETS_SCHEMA: dict[str, Any] = { "type": "object", - "properties": {"recordsets": {"type": "array", "items": RECORDSET_SCHEMA}}, + "properties": { + "recordsets": {"type": "array", "items": RECORDSET_SCHEMA}, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + "links": { + "type": "object", + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + }, "additionalProperties": False, } @@ -466,6 +602,128 @@ RECORDSETS_LIST_PARAMETERS: dict[str, Any] = { **ZONE_RECORDSETS_LIST_PARAMETERS, } +PTR_RECORD_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "uuid", + "readOnly": True, + "description": "ID for PTR record in the format of :", + }, + "ptrdname": { + "type": ["string", "null"], + "description": "Domain name for this PTR record", + }, + "description": { + "type": "string", + "description": "Description for this PTR record", + }, + "ttl": { + "type": "integer", + "description": "Time to live for this PTR record", + }, + "address": { + "type": "string", + "description": "The floatingip address for this PTR record.", + }, + "status": { + "type": "string", + "enum": PTR_STATUSES, + "readOnly": True, + "description": "The status of the resource.", + }, + "action": { + "type": "string", + "enum": PTR_ACTIONS, + "readOnly": True, + "description": "current action in progress on the resource", + }, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + }, +} + +PTR_RECORDS_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "floatingips": {"type": "array", "items": PTR_RECORD_SCHEMA}, + "links": { + "type": "object", + "readOnly": True, + "properties": {"self": {"type": "string", "format": "uri"}}, + }, + }, + "additionalProperties": False, +} + +PTR_RECORDS_LIST_PARAMETERS: dict[str, Any] = { + "x-auth-all-projects": { + "in": "header", + "name": "x-auth-all-projects", + "description": "If enabled this will show results from all projects in Designate", + "schema": {"type": "bool"}, + }, + "x-auth-sudo-project-id": { + "in": "header", + "name": "x-auth-sudo-project-id", + "description": "This allows a user to impersonate another project", + "schema": {"type": "string"}, + }, +} + +LIMITS_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "max_page_limit": { + "type": "integer", + "description": "The max amount of items allowed per page.", + }, + "max_recordset_name_length": { + "type": "integer", + "description": "The max length of a recordset name.", + }, + "max_recordset_records": { + "type": "integer", + "description": "The max amount of records contained in a recordset.", + }, + "max_zone_name_length": { + "type": "integer", + "description": "The max length of a zone name.", + }, + "max_zone_records": { + "type": "integer", + "description": "The max amount of records in a zone.", + }, + "max_zone_recordsets": { + "type": "integer", + "description": "The max amount of recordsets per zone.", + }, + "max_zones": { + "type": "integer", + "description": "The max amount of zones for this project.", + }, + "min_ttl": { + "type": "integer", + "description": "The lowest ttl allowed on this system.", + }, + }, +} + +QUOTAS_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "api_export_size": {"type": "integer"}, + "recordset_records": {"type": "integer"}, + "zone_records": {"type": "integer"}, + "zone_recorsets": {"type": "integer"}, + "zones": {"type": "integer"}, + }, +} + def _post_process_operation_hook( openapi_spec, operation_spec, path: str | None = None @@ -496,6 +754,22 @@ def _post_process_operation_hook( 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 == "zones/zone_id/shares:get": + for key, val in ZONE_SHARES_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 == "reverse/floatingips:get": + for key, val in PTR_RECORDS_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)) def _get_schema_ref( @@ -532,6 +806,41 @@ def _get_schema_ref( **NAMESERVERS_SCHEMA ) ref = f"#/components/schemas/{name}" + if name in [ + "ZonesShareShowResponse", + "ZonesSharesCreateRequest", + "ZonesSharesCreateResponse", + ]: + openapi_spec.components.schemas[name] = TypeSchema(**ZONE_SHARE_SCHEMA) + ref = f"#/components/schemas/{name}" + elif name in ["ZonesSharesListResponse"]: + openapi_spec.components.schemas[name] = TypeSchema( + **ZONE_SHARES_SCHEMA + ) + ref = f"#/components/schemas/{name}" + elif name in ["ReverseFloatingipsListResponse"]: + openapi_spec.components.schemas[name] = TypeSchema( + **PTR_RECORDS_SCHEMA + ) + ref = f"#/components/schemas/{name}" + elif name in [ + "ReverseFloatingipShowResponse", + "ReverseFloatingipUpdateRequest", + "ReverseFloatingipUpdateResponse", + ]: + openapi_spec.components.schemas[name] = TypeSchema(**PTR_RECORD_SCHEMA) + ref = f"#/components/schemas/{name}" + elif name in ["LimitsListResponse"]: + openapi_spec.components.schemas[name] = TypeSchema(**LIMITS_SCHEMA) + ref = f"#/components/schemas/{name}" + elif name in [ + "QuotasListResponse", + "QuotaShowResponse", + "QuotaUpdateRequest", + "QuotaUpdateResponse", + ]: + openapi_spec.components.schemas[name] = TypeSchema(**QUOTAS_SCHEMA) + ref = f"#/components/schemas/{name}" else: return (None, None, False) diff --git a/metadata/dns_metadata.yaml b/metadata/dns_metadata.yaml index 87932e6..aadb216 100644 --- a/metadata/dns_metadata.yaml +++ b/metadata/dns_metadata.yaml @@ -761,13 +761,3 @@ resources: module_name: set sdk_mod_name: set cli_full_command: quota set - list: - operation_id: quotas:get - operation_type: list - targets: - rust-sdk: - module_name: list - rust-cli: - module_name: list - sdk_mod_name: list - cli_full_command: quota list