- Lean's API WIP on forms and ApiRenderer

This commit is contained in:
Dave Mc Nicoll committed 2025-05-21 18:36:19 +00:00
1 parent 3ce356e1f2
commit 4d7053a9cb
30 files changed
+1003 -56

No files matched your search

+21 -7
View File
@@ -15,7 +15,6 @@ class FormDescriptor
foreach($forms as $form) {
$fields = [];
$propertyHtml = "";
$formName = is_object($form) ? $form::class : $form;
$reflector = new ObjectReflection($formName);
@@ -24,17 +23,19 @@ class FormDescriptor
foreach($reflector->reflectProperties() as $property) {
$field = $property->getAttribute(ContextField::class);
if ($field) {
if ($field && ! $field->object->hidden ) {
$types = $property->getTypes();
$fields[] = [
'name' => $property->name,
'description' => $field->object->description,
'type' => $field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),
'type' => $field->object->type ?? $types,
'allowNulls' => $property->allowsNull(),
'regexPattern' =>$field->object->regexFormat ?? "aucun",
'minLength' =>$field->object->minLength ?? "aucune",
'maxLength' =>$field->object->maxLength ?? "aucune",
'example' =>$field->object->example,
'regexPattern' => $field->object->regexFormat ?? null,
'minLength' => $field->object->minLength ?? null,
'maxLength' => $field->object->maxLength ?? null,
'example' => $field->object->example ?? null,
'values' => $this->generateExampleValues($types),
];
}
}
@@ -48,4 +49,17 @@ class FormDescriptor
return $list;
}
protected function generateExampleValues(array $types) : string|array
{
$values = [];
foreach($types as $type) {
if ( enum_exists($type->type) ) {
$values = array_merge($values, array_map(fn($e) => $e->value, $type->type::cases()));
}
}
return $values;
}
}