Skip to content

Commit

Permalink
Fix example generation
Browse files Browse the repository at this point in the history
  • Loading branch information
therve committed Oct 10, 2022
1 parent cae36d7 commit 1151293
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ def format_data_with_schema_list(
print(f"{e}")

if matched == 0:
raise ValueError(f"[{matched}] {data} is not valid for schema {name}")
raise ValueError(f"[{matched}] {data} is not valid for schema {schema}")
elif matched > 1:
warnings.warn(f"[{matched}] {data} is not valid for schema {name}")
warnings.warn(f"[{matched}] {data} is not valid for schema {schema}")

one_of_schema_name = simple_type(one_of_schema) or f"{schema_name(one_of_schema)}"
reference = "" if one_of_schema.get("required", False) else "&"
Expand Down Expand Up @@ -684,7 +684,14 @@ def format_data_with_schema_dict(
return f"{reference}{name_prefix}{name}{{\n{one_of_schema_name}: {parameters}}}"

if schema.get("type") == "object" and "properties" not in schema:
return "new(interface{})"
if schema.get("additionalProperties") == {}:
name_prefix = ""
name = "map[string]interface{}"
reference = ""
for k, v in data.items():
parameters += f'"{k}": "{v}",\n'
else:
return "new(interface{})"

if not name:
warnings.warn(f"Unnamed schema {schema} for {data}")
Expand Down

0 comments on commit 1151293

Please sign in to comment.