diff --git a/codegenerator/metadata.py b/codegenerator/metadata.py index f672748..8d6bf83 100644 --- a/codegenerator/metadata.py +++ b/codegenerator/metadata.py @@ -702,6 +702,14 @@ def post_process_compute_operation( def post_process_identity_operation( resource_name: str, operation_name: str, operation ): + if resource_name == "role/imply": + if operation_name == "list": + operation.targets["rust-cli"].response_key = "role_inference" + operation.targets["rust-sdk"].response_key = "role_inference" + if resource_name == "role_inference": + if operation_name == "list": + operation.targets["rust-cli"].response_key = "role_inferences" + operation.targets["rust-sdk"].response_key = "role_inferences" return operation diff --git a/codegenerator/openapi/cinder_schemas.py b/codegenerator/openapi/cinder_schemas.py index 8025009..944e920 100644 --- a/codegenerator/openapi/cinder_schemas.py +++ b/codegenerator/openapi/cinder_schemas.py @@ -23,7 +23,7 @@ "type": "object", "description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.", "properties": { - "href": {"type": "string", "format": "url"}, + "href": {"type": "string", "format": "uri"}, "rel": {"type": "string"}, }, } diff --git a/codegenerator/openapi/keystone_schemas/auth.py b/codegenerator/openapi/keystone_schemas/auth.py index 9ea8124..64e45b9 100644 --- a/codegenerator/openapi/keystone_schemas/auth.py +++ b/codegenerator/openapi/keystone_schemas/auth.py @@ -363,7 +363,7 @@ }, "url": { "type": "string", - "format": "url", + "format": "uri", "description": "The endpoint url", }, }, diff --git a/codegenerator/openapi/keystone_schemas/common.py b/codegenerator/openapi/keystone_schemas/common.py index d86b014..1c86ca9 100644 --- a/codegenerator/openapi/keystone_schemas/common.py +++ b/codegenerator/openapi/keystone_schemas/common.py @@ -21,7 +21,7 @@ "type": "object", "description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.", "properties": { - "href": {"type": "string", "format": "url"}, + "href": {"type": "string", "format": "uri"}, "rel": {"type": "string"}, }, } diff --git a/codegenerator/openapi/keystone_schemas/domain.py b/codegenerator/openapi/keystone_schemas/domain.py index 4e99b79..f4b5f82 100644 --- a/codegenerator/openapi/keystone_schemas/domain.py +++ b/codegenerator/openapi/keystone_schemas/domain.py @@ -39,7 +39,7 @@ "properties": { "url": { "type": "string", - "format": "url", + "format": "uri", "description": "The LDAP URL.", }, "user_tree_dn": { diff --git a/codegenerator/openapi/keystone_schemas/endpoint.py b/codegenerator/openapi/keystone_schemas/endpoint.py index d8dcb34..5f20ec9 100644 --- a/codegenerator/openapi/keystone_schemas/endpoint.py +++ b/codegenerator/openapi/keystone_schemas/endpoint.py @@ -36,7 +36,7 @@ }, "region": { "type": "string", - "description": "The geographic location of the service ", + "description": "The geographic location of the service endpoint.", "x-openstack": {"max-ver": "3.2"}, }, "region_id": { @@ -52,7 +52,7 @@ }, "url": { "type": "string", - "format": "url", + "format": "uri", "description": "The endpoint URL.", }, }, diff --git a/codegenerator/openapi/keystone_schemas/region.py b/codegenerator/openapi/keystone_schemas/region.py index 5214043..7c52e24 100644 --- a/codegenerator/openapi/keystone_schemas/region.py +++ b/codegenerator/openapi/keystone_schemas/region.py @@ -25,12 +25,12 @@ "id": { "type": "string", "format": "uuid", - "description": "The ID for the ", + "description": "The ID for the region.", }, "parent_id": { "type": "string", "format": "uuid", - "description": "To make this region a child of another region, set this parameter to the ID of the parent ", + "description": "To make this region a child of another region, set this parameter to the ID of the parent region.", }, }, } diff --git a/codegenerator/openapi/keystone_schemas/role.py b/codegenerator/openapi/keystone_schemas/role.py index 613931d..fc5a738 100644 --- a/codegenerator/openapi/keystone_schemas/role.py +++ b/codegenerator/openapi/keystone_schemas/role.py @@ -24,7 +24,7 @@ "id": { "type": "string", "format": "uuid", - "description": "The role ID", + "description": "The role ID.", }, "links": {"type": "object"}, **assignment_schema._role_properties, @@ -37,11 +37,25 @@ "id": { "type": "string", "format": "uuid", - "description": "The role ID", + "description": "The role ID.", }, "name": { "type": "string", - "description": "The role name", + "description": "The role name.", + }, + "description": { + "type": "string", + "description": "The role description.", + }, + "links": { + "type": "object", + "properties": { + "self": { + "type": "string", + "format": "uri", + "description": "The link to the resource in question.", + } + }, }, }, } @@ -55,15 +69,26 @@ }, } +# Role list specific query parameters +ROLE_LIST_PARAMETERS: dict[str, Any] = { + "role_domain_id": { + "in": "query", + "name": "domain_id", + "description": "Filters the response by a domain ID.", + "schema": {"type": "string", "format": "uuid"}, + }, +} + ROLE_INFERENCE_SCHEMA: dict[str, Any] = { "type": "object", "properties": { "role_inference": { + "type": "object", "properties": { - "prior_role": ROLE_SCHEMA, - "implies": ROLE_SCHEMA, - } + "prior_role": ROLE_INFO_SCHEMA, + "implies": ROLE_INFO_SCHEMA, + }, } }, } @@ -72,13 +97,33 @@ "type": "object", "properties": { "role_inference": { + "type": "object", "properties": { - "prior_role": ROLE_SCHEMA, + "prior_role": ROLE_INFO_SCHEMA, "implies": { "type": "array", - "items": ROLE_SCHEMA, + "items": ROLE_INFO_SCHEMA, }, - } + }, + } + }, +} + +ROLES_INFERENCES_SCHEMA: dict[str, Any] = { + "type": "object", + "properties": { + "role_inferences": { + "type": "array", + "items": { + "type": "object", + "properties": { + "prior_role": ROLE_INFO_SCHEMA, + "implies": { + "type": "array", + "items": ROLE_INFO_SCHEMA, + }, + }, + }, } }, } @@ -130,12 +175,12 @@ "properties": { "assignment": { "type": "string", - "format": "url", + "format": "uri", "description": "a link to the assignment that gave rise to this entity", }, "membership": { "type": "string", - "format": "url", + "format": "uri", }, }, }, @@ -224,7 +269,19 @@ def _post_process_operation_hook( """Hook to allow service specific generator to modify details""" operationId = operation_spec.operationId - if operationId == "role_assignments:get": + if operationId == "roles:get": + for ( + key, + val, + ) in ROLE_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 == "role_assignments:get": for map in [ ROLE_ASSIGNMENTS_QUERY_PARAMETERS, ROLE_ASSIGNMENT_LIST_PARAMETERS, @@ -240,7 +297,7 @@ def _post_process_operation_hook( if ref not in [x.ref for x in operation_spec.parameters]: operation_spec.parameters.append(ParameterSchema(ref=ref)) - if operationId == "role_assignments:head": + elif operationId == "role_assignments:head": for ( key, val, @@ -318,6 +375,12 @@ def _get_schema_ref( name, TypeSchema(**ROLE_ASSIGNMENTS_SCHEMA) ) ref = f"#/components/schemas/{name}" + # Role Inferences + elif name == "Role_InferencesGetResponse": + openapi_spec.components.schemas.setdefault( + name, TypeSchema(**ROLES_INFERENCES_SCHEMA) + ) + ref = f"#/components/schemas/{name}" # Project/Domain Roles elif name == "ProjectsUsersRolesGetResponse": diff --git a/codegenerator/openapi/nova_schemas.py b/codegenerator/openapi/nova_schemas.py index c14741c..2963085 100644 --- a/codegenerator/openapi/nova_schemas.py +++ b/codegenerator/openapi/nova_schemas.py @@ -25,7 +25,7 @@ "type": "object", "description": "Links to the resources in question. See [API Guide / Links and References](https://docs.openstack.org/api-guide/compute/links_and_references.html) for more info.", "properties": { - "href": {"type": "string", "format": "url"}, + "href": {"type": "string", "format": "uri"}, "rel": {"type": "string"}, }, } @@ -477,7 +477,7 @@ }, "url": { "type": "string", - "format": "url", + "format": "uri", "description": "The URL is used to connect the console.", }, }, diff --git a/metadata/identity_metadata.yaml b/metadata/identity_metadata.yaml index 23c66af..76b6275 100644 --- a/metadata/identity_metadata.yaml +++ b/metadata/identity_metadata.yaml @@ -2294,15 +2294,17 @@ resources: targets: rust-sdk: module_name: head - get: + list: operation_id: role_inferences:get - operation_type: get + operation_type: list targets: rust-sdk: - module_name: get + module_name: list + response_key: role_inferences rust-cli: - module_name: get - sdk_mod_name: get + module_name: list + sdk_mod_name: list + response_key: role_inferences identity.role: spec_file: wrk/openapi_specs/identity/v3.yaml api_version: v3 @@ -2387,9 +2389,11 @@ resources: targets: rust-sdk: module_name: list + response_key: role_inference rust-cli: module_name: list sdk_mod_name: list + response_key: role_inference show: operation_id: roles/prior_role_id/implies/implied_role_id:get operation_type: show diff --git a/tools/generate_rust_identity.sh b/tools/generate_rust_identity.sh index 7ebd282..22f45ee 100755 --- a/tools/generate_rust_identity.sh +++ b/tools/generate_rust_identity.sh @@ -12,6 +12,8 @@ NET_RESOURCES=( "endpoint" "region" "role_assignment" + "role_inference" + "role" ) openstack-codegenerator --work-dir ${WRK_DIR} --target rust-sdk --metadata ${METADATA}/identity_metadata.yaml --service identity