Skip to content

Commit

Permalink
Hide OneOfSchema Attributes (#139)
Browse files Browse the repository at this point in the history
* add a potential fix for filtering identifiers

* rm dead code

* make a metadata class

Signed-off-by: Matthew F Leader <[email protected]>

* override parent method in child class

* rm dead code

Signed-off-by: Matthew F Leader <[email protected]>

* change not implemented error msg

Signed-off-by: Matthew F Leader <[email protected]>

* rm dead code

Signed-off-by: Matthew F Leader <[email protected]>

* start test case

Signed-off-by: Matthew F Leader <[email protected]>

* rm dead code

Signed-off-by: Matthew F Leader <[email protected]>

* test case

Signed-off-by: Matthew F Leader <[email protected]>

* rm dead code

* rm dead code

* rm dead code

* rm dead code

* fix style

* rm dead code

* change to use properties

* document purpose of functions

---------

Signed-off-by: Matthew F Leader <[email protected]>
  • Loading branch information
mfleader authored Sep 5, 2024
1 parent b87ebc8 commit 6dcecbd
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions src/arcaflow_plugin_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2525,8 +2525,10 @@ class ObjectSchema(_JSONSchemaGenerator, _OpenAPIGenerator):
id_unenforced: typing.Annotated[
typing.Optional[bool],
_name("ID Unenforced"),
_description("If true, the ID does not need to match another object "
"for them to be considered compatible."),
_description(
"If true, the ID does not need to match another object "
"for them to be considered compatible."
),
] = None

def _to_jsonschema_fragment(
Expand Down Expand Up @@ -2597,10 +2599,6 @@ class OneOfSchema(_JSONSchemaGenerator, _OpenAPIGenerator):
" objects' schema"
),
]
oneof_type: typing.Annotated[str, _name("One Of Type Schema Name")] = None
discriminator_type: typing.Annotated[str, _name("Discriminator Type")] = (
None
)
discriminator_field_name: typing.Annotated[
str,
_name("Discriminator field name"),
Expand All @@ -2609,6 +2607,24 @@ class OneOfSchema(_JSONSchemaGenerator, _OpenAPIGenerator):
),
] = "_type"

@property
def oneof_type(self) -> str:
"""This internal state is implemented as a property because ALL of this
class's attributes (public and hidden) are used to define the
specification of this Arcaflow type."""
raise NotImplementedError(
"oneof_type() is not implemented in the subclass"
)

@property
def discriminator_type(self) -> str:
"""This internal state is implemented as a property because ALL of this
class's attributes (public and hidden) are used to define the
specification of this Arcaflow type."""
raise NotImplementedError(
"discriminator_type() is not implemented in the subclass"
)

def _insert_discriminator(
self,
discriminated_object: typing.Dict[str, typing.Any],
Expand Down Expand Up @@ -2815,9 +2831,13 @@ class OneOfStringSchema(OneOfSchema):

types: Dict[str, typing.Annotated[_OBJECT_LIKE, discriminator("type_id")]]

def __post_init__(self):
self.oneof_type = "_discriminated_string_"
self.discriminator_type = "string"
@property
def oneof_type(self) -> str:
return "_discriminated_string_"

@property
def discriminator_type(self) -> str:
return "string"


@dataclass
Expand Down Expand Up @@ -2928,9 +2948,13 @@ class OneOfIntSchema(OneOfSchema):

types: Dict[int, typing.Annotated[_OBJECT_LIKE, discriminator("type_id")]]

def __post_init__(self):
self.oneof_type = "_discriminated_int_"
self.discriminator_type = "integer"
@property
def oneof_type(self) -> str:
return "_discriminated_int_"

@property
def discriminator_type(self) -> str:
return "integer"


@dataclass
Expand Down Expand Up @@ -6803,9 +6827,8 @@ def _resolve_forward(
# Note: This is an unstable API.
# noinspection PyProtectedMember
resolved = t._evaluate(
globalns=None,
localns=None,
recursive_guard=frozenset())
globalns=None, localns=None, recursive_guard=frozenset()
)
return cls._resolve(resolved, resolved, path, scope)

@classmethod
Expand Down

0 comments on commit 6dcecbd

Please sign in to comment.