Skip to content

Commit c6b8b8d

Browse files
docs(schemagen): Update/expand documentation on propertynaming
It seems this area of the documentation was a little out of date, I have updated it!
1 parent b2239c2 commit c6b8b8d

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

_docs/schema/schemagen/schema-generation.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,34 @@ There are four options:
270270
271271
### Property naming {#schema-schemagen-property-names}
272272
273-
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:
273+
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.
274274
275-
- `camelCase`
276-
- `PascalCase`
277-
- `kebab-case`
278-
- `UPPER-KEBAB-CASE`
279-
- `snake_case`
280-
- `UPPER_SNAKE_CASE`
275+
```C#
276+
SchemaGeneratorConfiguration config = new()
277+
{
278+
// All property names will be lowercase!
279+
PropertyNameResolver = x => x.Name.ToLower()
280+
};
281+
```
282+
283+
The `PropertyNameResolvers` static class defines a few commonly-used conventions:
284+
285+
| ResolvedName | Example |
286+
|----------------------------------------|---------------------|
287+
| PropertyNameResolvers.CamelCase | `camelCase` |
288+
| PropertyNameResolvers.PascalCase | `PascalCase` |
289+
| PropertyNameResolvers.KebabCase | `kebab-case` |
290+
| PropertyNameResolvers.UpperKebabCase | `UPPER-KEBAB-CASE` |
291+
| PropertyNameResolvers.SnakeCase | `snake_case` |
292+
| PropertyNameResolvers.UpperSnakeCase | `UPPER_SNAKE_CASE` |
281293
282-
Just set this property and the system will adjust property names accordingly.
294+
You can use them like this:
295+
```c#
296+
SchemaGeneratorConfiguration config = new()
297+
{
298+
PropertyNameResolver = PropertyNameResolvers.CamelCase
299+
};
300+
```
283301
284302
Note that the `[JsonPropertyName]` attribute takes precedence, so you can still use this to get custom naming when you've configured a method.
285303

0 commit comments

Comments
 (0)