-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ccaroon/support-oneOf
- Loading branch information
Showing
5 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import random | ||
from typing import Any, Dict, List, Optional | ||
|
||
from .base import BaseSchema, ProviderNotSetException | ||
|
||
|
||
class OneOf(BaseSchema): | ||
schemas: List[BaseSchema] = None | ||
|
||
def from_dict(d): | ||
return OneOf(**d) | ||
|
||
def generate(self, context: Dict[str, Any]) -> Optional[List[Any]]: | ||
try: | ||
return super().generate(context) | ||
except ProviderNotSetException: | ||
return random.choice(self.schemas).generate(context) | ||
|
||
def model(self, context: Dict[str, Any]): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"maxLength": 5 | ||
}, | ||
{ | ||
"type": "boolean" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters