Skip to content

Commit

Permalink
Fix: schema auto generated documentation and json schema (#2251)
Browse files Browse the repository at this point in the history
Co-authored-by: Claus Holbech <[email protected]>
  • Loading branch information
carlbuchmann and ClausHolbechArista authored Nov 3, 2022
1 parent 70413bd commit dfb1dcb
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ def items(self, schema: dict, indentation: int, var_path: list, table: str):

def required(self, schema: dict, var_name: str, parent_schema: dict):
output = None
if schema.get("required"):
if parent_schema and parent_schema.get("primary_key") == var_name:
output = "Required, Unique"
elif schema.get("required"):
output = "Required"
if parent_schema and parent_schema.get("primary_key") == var_name:
output = "Required, Unique"
return output

def default(self, schema: dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ def convert_default(self, default, parent_schema: dict) -> dict:
return {"default": default}

def convert_items(self, items: dict, parent_schema: dict) -> dict:
output = {"items": {}}
output["items"] = self.convert_schema(items)
if (primary_key := parent_schema.get("primary_key")) and output["items"]["type"] == "dict":
output["items"]["keys"][primary_key]["required"] = True
output = {
"items": self.convert_schema(items),
}
if (primary_key := parent_schema.get("primary_key")) and items.get("type") == "dict":
output["items"].setdefault("required", [])
if primary_key not in output["items"]["required"]:
output["items"]["required"].append(primary_key)
return output

def convert_display_name(self, display_name: str, parent_schema: dict) -> dict:
Expand Down
Loading

0 comments on commit dfb1dcb

Please sign in to comment.