settings-doc icon indicating copy to clipboard operation
settings-doc copied to clipboard

Issue rendering submodules

Open mssalvatore opened this issue 1 year ago • 0 comments

This is a follow-up from #15 .

Admittedly, what I'm trying to do is somewhat unorthodox. I'm not in love with Pydantic's "nested delimiter" feature. Personally, I'd rather not leak the structure of my configuration model outside of my application. If I decide to restructure my configuration models, I don't want everything that uses my application to need to modify the environment variables they set. In other words, I view the set of configuration parameters (i.e. environment variable names) as an interface that I'd like to be open to extension but closed for modification.

I have my configuration defined like this:

from pydantic_settings import BaseSettings, SettingsConfigDict

PREFIX = "MY_APP_"


class SubConfig(BaseSettings):
    model_config = SettingsConfigDict(env_prefix=f"{PREFIX}_SUB_", extra="ignore")
    field_a: int
    field_b: float


class Config(BaseSettings):
    model_config = SettingsConfigDict(env_prefix=PREFIX, extra="ignore")

    field_1: str
    field_2: bool
    sub: SubConfig

In practice, this lets me define environment variables like MY_APP_SUB_FIELD_A, without the need of a specific delimiter. settings-doc renders it as follows:

# `MY_APP_FIELD_1`

**Required**

# `MY_APP_FIELD_2`

**Required**

# `MY_APP_SUB`

**Required**

I'd like for settings-doc to traverse the subconfig and generate documentation for its members. Any help is appreciated.

mssalvatore avatar May 08 '24 17:05 mssalvatore