in src/sagemaker_core/tools/resources_codegen.py [0:0]
def generate_config_schema(self):
"""
Generates the Config Schema that is used by json Schema to validate config jsons .
This function creates a python file with a variable that is consumed in the scripts to further fetch configs.
Input for generating the Schema is the service JSON that is already loaded in the class
"""
resource_properties = {}
for _, row in self.resources_plan.iterrows():
resource_name = row["resource_name"]
# Get the operation and shape for the 'get' method
if self._is_get_in_class_methods(row["class_methods"]):
get_operation = self.operations["Describe" + resource_name]
get_operation_shape = get_operation["output"]["shape"]
# Generate the class attributes based on the shape
class_attributes = self.shapes_extractor.generate_shape_members(get_operation_shape)
cleaned_class_attributes = self._cleanup_class_attributes_types(class_attributes)
resource_name = row["resource_name"]
if default_attributes := self._get_dict_with_default_configurable_attributes(
cleaned_class_attributes
):
resource_properties[resource_name] = {
TYPE: OBJECT,
PROPERTIES: default_attributes,
}
combined_config_schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
TYPE: OBJECT,
PROPERTIES: {
SCHEMA_VERSION: {
TYPE: "string",
"enum": ["1.0"],
"description": "The schema version of the document.",
},
SAGEMAKER: {
TYPE: OBJECT,
PROPERTIES: {
PYTHON_SDK: {
TYPE: OBJECT,
PROPERTIES: {
RESOURCES: {
TYPE: OBJECT,
PROPERTIES: resource_properties,
}
},
"required": [RESOURCES],
}
},
"required": [PYTHON_SDK],
},
},
"required": [SAGEMAKER],
}
output = f"{GENERATED_CLASSES_LOCATION}/{CONFIG_SCHEMA_FILE_NAME}"
# Open the output file
with open(output, "w") as file:
# Generate and write the license to the file
file.write(
f"SAGEMAKER_PYTHON_SDK_CONFIG_SCHEMA = {json.dumps(combined_config_schema, indent=4)}"
)