Skip to content

Commit

Permalink
add possible values
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Jan 9, 2025
1 parent d7a327e commit c7b8536
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion django_setup_configuration/documentation/model_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import textwrap
from dataclasses import dataclass
from enum import Enum
from typing import Annotated, Any, Dict, Type, Union, get_args, get_origin
from typing import Annotated, Any, Dict, Type, Union, get_args, get_origin, Literal

import ruamel.yaml
from docutils import nodes
Expand Down Expand Up @@ -75,10 +75,17 @@ def insert_example_with_comments(
yaml_set_comment_with_max_length(
example_data, field_name, field_info.description, 80, indent=depth * 2
)

if default := get_default_from_field_info(field_info):
example_data.yaml_set_comment_before_after_key(
field_name, f"default value: {default}", indent=depth * 2
)

if get_origin(field_info.annotation) == Literal:
example_data.yaml_set_comment_before_after_key(
field_name, f"possible values: {get_args(field_info.annotation)}", indent=depth * 2
)

example_data.yaml_set_comment_before_after_key(
field_name, f"required: {field_info.is_required()}", indent=depth * 2
)
Expand Down

0 comments on commit c7b8536

Please sign in to comment.