Skip to content

Commit 991b241

Browse files
committed
config JsonOptions globally /3
1 parent 2f97ba2 commit 991b241

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

aspnetcore/fundamentals/openapi/include-metadata.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,24 +619,19 @@ public enum DayOfTheWeekAsString
619619
}
620620
```
621621

622-
A special case is when an enum type has the `[Flags]` attribute, which indicates that the enum can be treated as a bit field; that is, a set of flags. A flags enum with a `[JsonConverterAttribute]` is defined as `type: string` in the generated schema with no `enum` property, since the value could be any combination of the enum values. For example, the following enum:
622+
A special case is when an enum type has the `[Flags]` attribute, which indicates that the enum can be treated as a bit field; that is, a set of flags. A flags `enum` with a `[JsonConverterAttribute]` is defined as `type: string` in the generated schema with no `enum` property. No `enum` property is generated because the value could be any combination of the enum values. For example, the following `enum` could have values such as `"Pepperoni, Sausage"` or `"Sausage, Mushrooms, Anchovies"`:
623623

624624
```csharp
625625
[Flags, JsonConverter(typeof(JsonStringEnumConverter<PizzaToppings>))]
626626
public enum PizzaToppings { Pepperoni = 1, Sausage = 2, Mushrooms = 4, Anchovies = 8 }
627627
```
628628

629-
could have values such as `"Pepperoni, Sausage"` or `"Sausage, Mushrooms, Anchovies"`.
630-
631629
An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.JsonConverterAttribute) will be defined as `type: integer` in the generated schema.
632630

633-
**Note:** The [`[AllowedValues]`](xref:System.ComponentModel.DataAnnotations.AllowedValuesAttribute) attribute does not set the `enum` values of a property.
634-
635-
The following code shows how to configure JSON options globally, for Minimal APIs and Controler based APIs:
636-
637-
[!code-csharp[](~/fundamentals/openapi/samples/10.x/WebJson/Program.cs?highlight=8-39)]
631+
**Note:**
638632

639-
###
633+
* The [`[AllowedValues]`](xref:System.ComponentModel.DataAnnotations.AllowedValuesAttribute) attribute does not set the `enum` values of a property.
634+
* zz can be set globally, see
640635

641636
#### nullable
642637

@@ -674,6 +669,12 @@ An abstract class with a [`[JsonPolymorphic]`](xref:System.Text.Json.Serializati
674669

675670
A schema transformer can be used to override any default metadata or add additional metadata, such as `example` values, to the generated schema. See [Use schema transformers](xref:fundamentals/openapi/customize-openapi#use-schema-transformers) for more information.
676671

672+
## Set JSON serialization options globally
673+
674+
The following code shows how to configure JSON options globally, for Minimal APIs and Controler based APIs:
675+
676+
[!code-csharp[](~/fundamentals/openapi/samples/10.x/WebJson/Program.cs?highlight=8-39)]
677+
677678
## Additional resources
678679

679680
* <xref:fundamentals/openapi/using-openapi-documents>

0 commit comments

Comments
 (0)