Skip to content

Commit

Permalink
auto-generation of config documentations.
Browse files Browse the repository at this point in the history
  • Loading branch information
khajavi committed May 22, 2024
1 parent 8275264 commit c9af2a9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 73 deletions.
81 changes: 81 additions & 0 deletions docs/auto-generation-of-config-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
id: auto-generation-of-config-documentation
title: "Auto-generation of Config Documentation"
---

ZIO Config has a built-in support for generating documentation for the configuration descriptors. This feature is useful for library authors to provide documentation for their configuration stuff. No matter how we have defined our config descriptors, manually or automatically using magnolia, we can generate documentation for them.

## Example 1: Simple Configuration

```scala mdoc:silent
import utils._

printSource("examples/shared/src/main/scala/zio/config/examples/documentation/GeneratingConfigDocumentation.scala")
```

Here is the output:

```md
auto-generated documentation of MyConfig:

## Configuration Details


|FieldName|Format |Description|Sources|
|--- |--- |--- |--- |
| |[all-of](fielddescriptions)| | |

### Field Descriptions

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|LDAP |primitive|a text property, Related to auth | |
|PORT |primitive|an integer property, Database port| |
|DB_URL |primitive|a text property, URL of database | |
```

Currently, ZIO Config supports generating the documentation in two flavors: GitHub and Confluence markdown.

## Example 2: Nested Configuration

Here is another example, which includes nested configuration values:

```scala mdoc:silent
import utils._
printSource("examples/shared/src/main/scala/zio/config/examples/documentation/NestedConfigDocumentation.scala")
```

Let's see how the documentation looks like:

```md
Auto-generated documentation of AppConfig:

## Configuration Details


|FieldName|Format |Description|Sources|
|--- |--- |--- |--- |
| |[all-of](fielddescriptions)| | |

### Field Descriptions

|FieldName |Format |Description |Sources|
|--- |--- |--- |--- |
|SECRET |primitive |a text property, Application secret| |
|[CREDENTIALS](credentials)|[all-of](credentials)|Credentials | |
|[DATABASE](database) |[all-of](database) |Database | |

### CREDENTIALS

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|USERNAME |primitive|a text property, Example: ZioUser| |
|PASSWORD |primitive|a text property, Example: ZioPass| |

### DATABASE

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|PORT |primitive|an integer property, Example: 8088| |
|URL |primitive|a text property, Example: abc.com | |
```
73 changes: 0 additions & 73 deletions docs/dive-into-zio-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,79 +74,6 @@ val source = ConfigProvider.fromMap(map)
source.load(MyConfig.config)
```

## Generating Config Documentation

```scala mdoc:silent
import utils._

printSource("examples/shared/src/main/scala/zio/config/examples/documentation/GeneratingConfigDocumentation.scala")
```

Here is the output:

```md
auto-generated documentation of MyConfig:

## Configuration Details


|FieldName|Format |Description|Sources|
|--- |--- |--- |--- |
| |[all-of](fielddescriptions)| | |

### Field Descriptions

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|LDAP |primitive|a text property, Related to auth | |
|PORT |primitive|an integer property, Database port| |
|DB_URL |primitive|a text property, URL of database | |
```

Currently, ZIO Config supports generating the documentation in two flavors: GitHub and Confluence markdown.

Here is another example, which includes nested configuration values:

```scala mdoc:silent
import utils._
printSource("examples/shared/src/main/scala/zio/config/examples/documentation/NestedConfigDocumentation.scala")
```

Let's see how the documentation looks like:

```md
Auto-generated documentation of AppConfig:

## Configuration Details


|FieldName|Format |Description|Sources|
|--- |--- |--- |--- |
| |[all-of](fielddescriptions)| | |

### Field Descriptions

|FieldName |Format |Description |Sources|
|--- |--- |--- |--- |
|SECRET |primitive |a text property, Application secret| |
|[CREDENTIALS](credentials)|[all-of](credentials)|Credentials | |
|[DATABASE](database) |[all-of](database) |Database | |

### CREDENTIALS

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|USERNAME |primitive|a text property, Example: ZioUser| |
|PASSWORD |primitive|a text property, Example: ZioPass| |

### DATABASE

|FieldName|Format |Description |Sources|
|--- |--- |--- |--- |
|PORT |primitive|an integer property, Example: 8088| |
|URL |primitive|a text property, Example: abc.com | |
```

## Accumulating all errors

For any misconfiguration, the `ReadError` collects all of them with proper semantics: `AndErrors` and `OrErrors`.
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const sidebars = {
items: [
"index",
"dive-into-zio-config",
"auto-generation-of-config-documentation",
"integrations",
"automatic-derivation-of-config",
"read-from-various-sources",
Expand Down

0 comments on commit c9af2a9

Please sign in to comment.