Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(eos_designs): Validation of structured_config #3077

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ l3leaf:
id: 1

expected_error_message: >-
1 errors raised during conversion of input vars. 3 errors found during schema validation of input vars.
1 errors raised during conversion of input vars. 2 errors found during schema validation of input vars.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"required": { "$ref": "#/$defs/required" },
"deprecation": { "$ref": "#/$defs/deprecation" },
"$ref": { "$ref": "#/$defs/$ref" },
"documentation_options": { "$ref": "#/$defs/documentation_options" },
"documentation_options": { "$ref": "#/$defs/documentation_options_dict" },
"$schema": { "type": "string" },
"$id": { "type": "string" },
"$defs": { "$ref": "#/$defs/$defs" }
Expand Down Expand Up @@ -315,6 +315,18 @@
},
"additionalProperties": false
},
"documentation_options_dict": {
"type": "object",
"description": "Special options used for generating documentation",
"properties": {
"table": { "$ref": "#/$defs/documentation_options/properties/table" },
"hide_keys": {
"type": "boolean",
"description": "Prevent keys of the dict from being displayed in the generated documentation.\nThis is used for structured_config where we wish to avoid displaying the full eos_cli_config_gen schema everywhere."
}
},
"additionalProperties": false
},
"$defs": {
"type": "object",
"description": "Storage for reusable schema fragments",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,28 @@ def build_table(self, table: str, schema: dict):
if table not in self._get_tables(childschema):
# Skip key if none of the underlying keys have the relevant table
continue
built_table["table"].extend(self.build_table_row(var_name=key, schema=childschema, indentation=0, var_path=[], table=table))
built_table["table"].extend(
self.build_table_row(
var_name=key,
schema=childschema,
indentation=0,
var_path=[],
table=table,
)
)
built_table["yaml"].extend(self.build_yaml_row(var_name=key, schema=childschema, indentation=0, table=table))

return built_table

def build_table_row(
self, var_name: str, schema: dict, indentation: int, var_path: list, table: str, parent_schema: dict = None, first_list_item_key: bool = False
self,
var_name: str,
schema: dict,
indentation: int,
var_path: list,
table: str,
parent_schema: dict = None,
first_list_item_key: bool = False,
):
output = []

Expand Down Expand Up @@ -183,7 +198,14 @@ def build_table_row(

return output

def build_yaml_row(self, var_name: str, schema: dict, indentation: int, table: str, first_list_item_key: bool = False):
def build_yaml_row(
self,
var_name: str,
schema: dict,
indentation: int,
table: str,
first_list_item_key: bool = False,
):
output = []

deprecation_label = get_deprecation(schema)[0]
Expand All @@ -198,7 +220,7 @@ def build_yaml_row(self, var_name: str, schema: dict, indentation: int, table: s
row = f"{row_indentation}{var_name}:"
var_type = schema.get("type")

if var_type == "dict" and (schema_keys := self._get_keys(schema)):
if var_type == "dict" and (schema_keys := self._get_keys(schema)) and not schema.get("documentation_options", {}).get("hide_keys"):
output.append(row)
for key, childschema in schema_keys.items():
if table not in self._get_tables(childschema):
Expand Down Expand Up @@ -287,6 +309,12 @@ def type(self, schema: dict):

def keys(self, schema: dict, indentation: int, var_path: list, table: str):
output = []

if schema.get("documentation_options", {}).get("hide_keys"):
# Skip documenting the keys.
# Used for not including all of eos_cli_config_gen for structured_config keys.
return output

schema_keys = self._get_keys(schema)

for key, childschema in schema_keys.items():
Expand Down
Loading