@@ -66,12 +66,21 @@ Here is an overview of the schemas used in somesy.
6666import json
6767from io import StringIO
6868from somesy.core.models import SomesyInput, ProjectMetadata, Person, SomesyConfig
69+ from pydantic_core import PydanticUndefined
70+ from typing_extensions import get_args
71+
72+ def pp_type (th ):
73+ # NOTE : this does not work correctly with non-trivial unions!
74+ while args := get_args(th):
75+ th = args[0 ]
76+ return th.__name__
6977
7078def fmt_desc (desc , pref = " " ):
7179 if not desc:
7280 return " "
7381 return " \n " .join(map (lambda x : pref + x.strip(), desc.split(" \n " )))
7482
83+
7584def model2md (m , out = None ):
7685 out = out or StringIO()
7786
@@ -80,20 +89,15 @@ def model2md(m, out = None):
8089 out.write(" \t\n\n " )
8190 out.write(" \t | Field | Type | Required? | Default | Description |\n " )
8291 out.write(" \t | ----- | ---- | --------- | ------- | ----------- |\n " )
83- for fld in m.__fields__.values():
84- n = fld.name
85-
86- t = fld.type_.__name__
87- if t == " ConstrainedStrValue" :
88- t = " str"
89- if t == " AnyUrl" :
90- t = " URL"
91- if fld.field_info.min_items:
92- t = f " list[ { t} ] "
93-
94- r = " **yes**" if fld.required else " no"
95- v = json.dumps(fld.default, default = str ) if fld.default is not None else " "
96- d = fmt_desc(fld.field_info.description)
92+ for n, fld in m.model_fields.items():
93+ t = pp_type(fld.annotation)
94+ r = " **yes**" if fld.is_required() else " no"
95+ dv = fld.default
96+ if dv is not None and dv != PydanticUndefined:
97+ v = json.dumps(fld.default, default = str )
98+ else :
99+ v = " "
100+ d = fmt_desc(fld.description)
97101 out.write(f " \t | { n} | { t} | { r} | { v} | { d} | \n " )
98102 out.write(" \n " )
99103
0 commit comments