From c6b8b8ded2ca08c748fb158f84402806ec705a6a Mon Sep 17 00:00:00 2001 From: ProbablePrime Date: Mon, 25 Nov 2024 00:01:28 -0800 Subject: [PATCH 1/4] docs(schemagen): Update/expand documentation on propertynaming It seems this area of the documentation was a little out of date, I have updated it! --- _docs/schema/schemagen/schema-generation.md | 34 ++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/_docs/schema/schemagen/schema-generation.md b/_docs/schema/schemagen/schema-generation.md index 3b3cb5ad..a54e8f7b 100644 --- a/_docs/schema/schemagen/schema-generation.md +++ b/_docs/schema/schemagen/schema-generation.md @@ -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. From 4669eb0001ec5a519b53c2418307b42e53e7609e Mon Sep 17 00:00:00 2001 From: ProbablePrime Date: Sun, 1 Dec 2024 14:08:09 -0800 Subject: [PATCH 2/4] Update _docs/schema/schemagen/schema-generation.md Co-authored-by: Greg Dennis --- _docs/schema/schemagen/schema-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/schema/schemagen/schema-generation.md b/_docs/schema/schemagen/schema-generation.md index a54e8f7b..1d0aa858 100644 --- a/_docs/schema/schemagen/schema-generation.md +++ b/_docs/schema/schemagen/schema-generation.md @@ -270,7 +270,7 @@ There are four options: ### Property naming {#schema-schemagen-property-names} -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. +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. ```C# SchemaGeneratorConfiguration config = new() From b68df4ce4fd7bf21b4b7107f307bdcc1e51a4be4 Mon Sep 17 00:00:00 2001 From: ProbablePrime Date: Sun, 1 Dec 2024 14:08:15 -0800 Subject: [PATCH 3/4] Update _docs/schema/schemagen/schema-generation.md Co-authored-by: Greg Dennis --- _docs/schema/schemagen/schema-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/schema/schemagen/schema-generation.md b/_docs/schema/schemagen/schema-generation.md index 1d0aa858..4ae16c79 100644 --- a/_docs/schema/schemagen/schema-generation.md +++ b/_docs/schema/schemagen/schema-generation.md @@ -280,7 +280,7 @@ SchemaGeneratorConfiguration config = new() }; ``` -The `PropertyNameResolvers` static class defines a few commonly-used conventions: +For your convenience, the `PropertyNameResolvers` static class defines a few commonly-used conventions: | ResolvedName | Example | |----------------------------------------|---------------------| From 0be315838c5a275113c1dd3ad6de6cc1e5e5fb25 Mon Sep 17 00:00:00 2001 From: ProbablePrime Date: Sun, 1 Dec 2024 14:08:19 -0800 Subject: [PATCH 4/4] Update _docs/schema/schemagen/schema-generation.md Co-authored-by: Greg Dennis --- _docs/schema/schemagen/schema-generation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_docs/schema/schemagen/schema-generation.md b/_docs/schema/schemagen/schema-generation.md index 4ae16c79..aba858f3 100644 --- a/_docs/schema/schemagen/schema-generation.md +++ b/_docs/schema/schemagen/schema-generation.md @@ -291,7 +291,8 @@ For your convenience, the `PropertyNameResolvers` static class defines a few com | PropertyNameResolvers.SnakeCase | `snake_case` | | PropertyNameResolvers.UpperSnakeCase | `UPPER_SNAKE_CASE` | -You can use them like this: +They can be applied directly to the configuration property: + ```c# SchemaGeneratorConfiguration config = new() {