ghandic/jsf

Use random type when field is nullable

Closed this issue · 5 comments

In the following line:

raise TypeError # pragma: no cover - not currently supporting other types TODO

A TypeError is raised when the item type represents more than one type (excluding null). I'm not sure why.

Can this method just return a random type from the list (including null)?

So:

import random

...

def __is_field_nullable(self, schema: Dict[str, Any]) -> Tuple[str, bool]:
    item_type = schema.get("type")
    if isinstance(item_type, list):
        if "null" in item_type:
            return random.choice(item_type), True
    return item_type, False

Absolutely! Looks like an artifact of building too specific to a spec I had. Please raise a PR

Could you run the test locally and get it passing? Looks like theres further changes required. I'll revert the merge until then

My apologies, the PR above passes tests locally (and in the pipeline).

Thanks for merging. When do you think you'll be making a new release? Thanks!