Source code for aac.plugins.unique_root_keys.unique_root_keys_impl
"""The AaC Unique Root Keys plugin implementation module."""# NOTE: It is safe to edit this file.# This file is only initially generated by aac gen-plugin, and it won't be overwritten if the file already exists.fromaac.execute.aac_execution_resultimport(ExecutionResult,ExecutionStatus,ExecutionMessage,MessageLevel,)fromaac.context.language_contextimportLanguageContextplugin_name="Unique Root Keys"
[docs]defroot_key_names_are_unique(context:LanguageContext)->ExecutionResult:"""Business logic for the Root key names are unique constraint."""status=ExecutionStatus.SUCCESSmessages:list[ExecutionMessage]=[]root_keys=[]fordefinitionincontext.get_definitions():ifdefinition.get_root_key()=="schema":ifdefinition.instance.root:ifdefinition.instance.rootnotinroot_keys:root_keys.append(definition.instance.root)else:status=ExecutionStatus.CONSTRAINT_FAILUREerror_msg=ExecutionMessage(f"Root key {definition.instance.root} is not unique.",MessageLevel.ERROR,"No file to reference"ifnotdefinition.sourceordefinition.source.uri=="<string>"elsedefinition.source.uri,None,)messages.append(error_msg)returnExecutionResult(plugin_name,"Root key names are unique",status,messages)