Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(schemagen): Update/expand documentation on propertynaming #21

Merged
merged 4 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions _docs/schema/schemagen/schema-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,35 @@ There are four options:

### Property naming {#schema-schemagen-property-names}

In addition to the `[JsonPropertyName]` attribute, the configuration exposes a `PropertyNamingMethod` that allows you to define a custom method for altering property names from your code into the schema. The `PropertyNamingMethods` static class defines a few commonly-used conventions:
In addition to the `[JsonPropertyName]` attribute, `SchemaGeneratorConfiguration.PropertyNameResolver` allows you to define a custom method for altering property names from your code into the schema. The system will adjust property names accordingly.

- `camelCase`
- `PascalCase`
- `kebab-case`
- `UPPER-KEBAB-CASE`
- `snake_case`
- `UPPER_SNAKE_CASE`
```C#
SchemaGeneratorConfiguration config = new()
{
// All property names will be lowercase!
PropertyNameResolver = x => x.Name.ToLower()
};
```

For your convenience, the `PropertyNameResolvers` static class defines a few commonly-used conventions:

| ResolvedName | Example |
|----------------------------------------|---------------------|
| PropertyNameResolvers.CamelCase | `camelCase` |
| PropertyNameResolvers.PascalCase | `PascalCase` |
| PropertyNameResolvers.KebabCase | `kebab-case` |
| PropertyNameResolvers.UpperKebabCase | `UPPER-KEBAB-CASE` |
| PropertyNameResolvers.SnakeCase | `snake_case` |
| PropertyNameResolvers.UpperSnakeCase | `UPPER_SNAKE_CASE` |

Just set this property and the system will adjust property names accordingly.
They can be applied directly to the configuration property:

```c#
SchemaGeneratorConfiguration config = new()
{
PropertyNameResolver = PropertyNameResolvers.CamelCase
};
```

Note that the `[JsonPropertyName]` attribute takes precedence, so you can still use this to get custom naming when you've configured a method.

Expand Down