MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / jsonschema_for_single_field

Function jsonschema_for_single_field

etc/scripts/sch2js/sch2js.py:71–90  ·  view source on GitHub ↗

Return a mapping for the schema of a single field.

(field_instance)

Source from the content-addressed store, hash-verified

69 }
70
71 def jsonschema_for_single_field(field_instance):
72 """
73 Return a mapping for the schema of a single field.
74 """
75 field_schema = {}
76
77 field_schema["type"] = SCHEMATIC_TYPE_TO_JSON_TYPE.get(
78 field_instance.__class__.__name__, "string"
79 )
80
81 if hasattr(field_instance, "metadata"):
82 field_schema["title"] = field_instance.metadata.get("label", "")
83 field_schema["description"] = field_instance.metadata.get("description", "")
84
85 for js_key, schematic_key in schema_kwargs_to_schematics.items():
86 value = getattr(field_instance, schematic_key, None)
87 if value is not None:
88 field_schema[js_key] = value
89
90 return field_schema
91
92 def jsonschema_for_fields(model):
93 """

Callers 1

jsonschema_for_fieldsFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected