Skip to content

Commit

Permalink
BF: do not bother workarounding enum for schemaKey if there is None
Browse files Browse the repository at this point in the history
Somehow I do not run into this behavior with pydantic 1.8.2 when using custom
metaclass.  Might be a sign of trouble but all tests pass, so I decided just
to condition on having "enum".   But then saw that resultant schema lacks "const"
so reworked to add "const" even if not enum.  May be that is not desired?
  • Loading branch information
yarikoptic committed May 25, 2021
1 parent ecaeb88 commit 3f557ea
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dandischema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,13 @@ def schema_extra(schema: Dict[str, Any], model) -> None:
# In pydantic 1.8+ all Literals are mapped on to enum
# This presently breaks the schema editor UI. Revert
# to const when generating the schema.
# Note: this no longer happens with custom metaclass
if prop == "schemaKey":
if len(value["enum"]) == 1:
if "enum" in value and len(value["enum"]) == 1:
value["const"] = value["enum"][0]
del value["enum"]
else:
value["const"] = value["default"]


class PropertyValue(DandiBaseModel):
Expand Down

0 comments on commit 3f557ea

Please sign in to comment.