Skip to content

Commit

Permalink
Merge pull request #35 from AllenNeuralDynamics/fix-allow-enum-object
Browse files Browse the repository at this point in the history
Ensure non-native types implment `x-enumNames` attribute generation
  • Loading branch information
bruno-f-cruz authored Jun 12, 2024
2 parents baf96a4 + 4b69d34 commit e68cf5e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/DataSchemas/aind_behavior_services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.nullable_as_oneof = kwargs.get("nullable_as_oneof", True)
self.unions_as_oneof = kwargs.get("unions_as_oneof", True)
self.render_xenum_names = kwargs.get("render_xenum_names", True)
self.render_x_enum_names = kwargs.get("render_x_enum_names", True)

def nullable_schema(self, schema: core_schema.NullableSchema) -> JsonSchemaValue:
null_schema = {"type": "null"}
Expand Down Expand Up @@ -86,7 +86,8 @@ def enum_schema(self, schema: core_schema.EnumSchema) -> JsonSchemaValue:
elif types == {list}:
result["type"] = "array"

if (self.render_xenum_names) and (result["type"] != "string"):
_type = result.get("type", None)
if (self.render_x_enum_names) and (_type != "string"):
result["x-enumNames"] = [screaming_snake_case_to_pascal_case(v.name) for v in schema["members"]]

return result
Expand Down

0 comments on commit e68cf5e

Please sign in to comment.