in src/rpdk/core/project.py [0:0]
def __set_property_type(prop_type, single_type=True):
nonlocal prop
# mark down formatting of the target value - used for complex objects
# ($ref) and arrays of such objects
markdown_lambda = (
lambda fname, name: f'<a href="{fname}">{name}</a>' # noqa: B950, C0301
)
type_json = type_yaml = type_longform = "Unknown"
if prop_type in BASIC_TYPE_MAPPINGS:
# primitives should not occur for circular ref;
type_json = type_yaml = type_longform = BASIC_TYPE_MAPPINGS[prop_type]
elif prop_type == "array":
# lambdas to reuse formatting
markdown_json = (
lambda markdown_value: f"[ {markdown_value}, ... ]"
) # noqa: E731
markdown_yaml = lambda markdown_value: ( # noqa: E731
f"\n - {markdown_value}"
if single_type
else f"[ {markdown_value}, ... ]"
)
markdown_long = (
lambda markdown_value: f"List of {markdown_value}"
) # noqa: E731
# potential circular ref
# setting up markdown before going deep in the heap to reuse markdown
if "$ref" in prop["items"]:
sub_propname = prop["items"]["$ref"][1] # get target sub property
sub_proppath = (sub_propname,)
# calculating hypothetical markdown property before
# actually traversing it - this way it could be reused -
# same .md doc could be attached to both instances
hypothetical = markdown_lambda(
"-".join(sub_proppath).lower() + ".md", sub_propname
)
# assigning hypothetical .md file reference before circular
# property gets boundary so when boundary is hit it reuses
# the same document
self._marked_down_properties[propname] = {
jsontype: markdown_json(hypothetical),
yamltype: markdown_yaml(hypothetical),
longformtype: markdown_long(hypothetical),
}
# traverse nested propertes
prop["arrayitems"] = arrayitems = self._set_docs_properties(
propname, prop["items"], proppath
)
# arrayitems should be similar to markdown of hypothetical target
# if there is an object ref
# arrayitems are could not be used for hypothetical values
# as could not be populated before traversing down
type_json = markdown_json(arrayitems[jsontype])
type_yaml = markdown_yaml(arrayitems[yamltype])
type_longform = markdown_long(arrayitems[longformtype])
elif prop_type == "object":
template = self.env.get_template("docs-subproperty.md")
docs_path = self.root / "docs"
object_properties = (
prop.get("properties") or prop.get("patternProperties") or {}
)
type_json = type_yaml = type_longform = "Map"
if object_properties:
subproperty_name = " ".join(proppath)
subproperty_filename = "-".join(proppath).lower() + ".md"
subproperty_path = docs_path / subproperty_filename
type_json = type_yaml = type_longform = markdown_lambda(
subproperty_filename, propname
)
# potential circular ref
# setting up markdown before going deep in the heap
# to reuse markdown
self._marked_down_properties[propname] = {
jsontype: type_json,
yamltype: type_json,
longformtype: type_json,
}
prop["properties"] = {
name: self._set_docs_properties(name, value, proppath + (name,))
for name, value in object_properties.items()
}
LOG.debug(
"Writing docs %s: %s", subproperty_filename, subproperty_path
)
contents = template.render(
type_name=self.type_name,
subproperty_name=subproperty_name,
schema=prop,
)
self.safewrite(subproperty_path, contents)
prop[jsontype] = __join(prop.get(jsontype), type_json)
prop[yamltype] = __join(prop.get(yamltype), type_yaml)
prop[longformtype] = __join(prop.get(longformtype), type_longform)
if "enum" in prop:
prop["allowedvalues"] = prop["enum"]