Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
elecay committed Jan 25, 2024
1 parent 0251386 commit 28930e4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jsf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
}
),
initial_state: Dict[str, Any] = MappingProxyType({}),
allow_none_optionals: float = 0.0,
allow_none_optionals: float = 0.5,
):
self.root_schema = schema
self.definitions = {}
Expand Down
2 changes: 1 addition & 1 deletion jsf/schema_types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BaseSchema(BaseModel):
provider: Optional[str] = Field(None, alias="$provider")
set_state: Optional[Dict[str, str]] = Field(None, alias="$state")
is_nullable: bool = False
allow_none_optionals: float = 1.0
allow_none_optionals: float = 0.5

@classmethod
def from_dict(cls, d: Dict):
Expand Down
2 changes: 1 addition & 1 deletion jsf/schema_types/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def generate(self, context: Dict[str, Any]) -> Optional[float]:
_max = self.maximum

return float(
step * random.uniform(math.ceil(float(_min) / step), math.floor(float(_max) / step))
step * random.randint(math.ceil(float(_min) / step), math.floor(float(_max) / step))
)

def model(self, context: Dict[str, Any]):
Expand Down
6 changes: 2 additions & 4 deletions jsf/schema_types/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ def from_dict(cls, d: dict):
return Object(**d)

def should_keep(self, property_name: str) -> bool:
if random.uniform(0, 1) > self.allow_none_optionals or (
isinstance(self.required, list) and property_name in self.required
):
if isinstance(self.required, list) and property_name in self.required:
return True
return random.uniform(0, 1) < 0.5
return random.uniform(0, 1) > self.allow_none_optionals

def generate(self, context: Dict[str, Any]) -> Optional[Dict[str, Any]]:
try:
Expand Down

0 comments on commit 28930e4

Please sign in to comment.