Skip to content

Commit

Permalink
docs(schemagen): Update/expand documentation on propertynaming
Browse files Browse the repository at this point in the history
It seems this area of the documentation was a little out of date, I have updated it!
  • Loading branch information
ProbablePrime authored Nov 25, 2024
1 parent b2239c2 commit c6b8b8d
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions _docs/schema/schemagen/schema-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,34 @@ 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, the configuration(`SchemaGeneratorConfiguration`) exposes a `PropertyNameResolver` delegate that 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()
};
```
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.
You can use them like this:
```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

0 comments on commit c6b8b8d

Please sign in to comment.