in src/rpdk/core/contract/resource_generator.py [0:0]
def generate_string_strategy(schema):
try:
string_format = schema["format"]
except KeyError:
try:
regex = schema["pattern"]
except KeyError:
min_length = schema.get("minLength", 0)
max_length = schema.get("maxLength")
return text(
alphabet=characters(
min_codepoint=1, blacklist_categories=("Cc", "Cs")
),
min_size=min_length,
max_size=max_length,
)
# Issues in regex patterns can lead to subtle bugs. Also log `repr`,
# which makes escaped characters more obvious (unicode, whitespace)
LOG.debug("regex pattern %s/'%s'", repr(regex), regex)
if "minLength" in schema: # pragma: no cover
LOG.warning("found minLength used with pattern")
if "maxLength" in schema: # pragma: no cover
LOG.warning("found maxLength used with pattern")
return from_regex(terminate_regex(regex))
if "pattern" in schema: # pragma: no cover
LOG.warning("found pattern used with format")
if "minLength" in schema: # pragma: no cover
LOG.warning("found minLength used with format")
if "maxLength" in schema: # pragma: no cover
LOG.warning("found maxLength used with format")
regex = STRING_FORMATS[string_format]
return from_regex(regex)