| | | 1 | | #region Usings |
| | | 2 | | using System.Globalization; |
| | | 3 | | #endregion |
| | | 4 | | |
| | | 5 | | namespace ZhEaIsNsAaBn.Utilities.Swagger; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Sets the OpenAPI example for a property, parameter, class, struct or enum. Needs <see cref="SwaggerSchemaExampleFilt |
| | | 9 | | /// registered with Swashbuckle. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <example> |
| | | 12 | | /// <code> |
| | | 13 | | /// public sealed class CreateCustomerRequest |
| | | 14 | | /// { |
| | | 15 | | /// [ SwaggerSchemaExample( "Hassan" ) ] |
| | | 16 | | /// public string Name { get; init; } = ""; |
| | | 17 | | /// } |
| | | 18 | | /// </code> |
| | | 19 | | /// </example> |
| | | 20 | | [ AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Parameter | AttributeTargets.Prope |
| | | 21 | | public sealed class SwaggerSchemaExampleAttribute : Attribute |
| | | 22 | | { |
| | | 23 | | /// <summary>Uses a text example.</summary> |
| | | 24 | | /// <param name="example">The example value.</param> |
| | 176 | 25 | | public SwaggerSchemaExampleAttribute( string example ) => Example = example; |
| | | 26 | | |
| | | 27 | | /// <summary>Uses a number example, written with the invariant culture.</summary> |
| | | 28 | | /// <param name="example">The example value.</param> |
| | 72 | 29 | | public SwaggerSchemaExampleAttribute( int example ) => Example = example.ToString( CultureInfo.InvariantCulture ); |
| | | 30 | | |
| | | 31 | | /// <summary>Uses a <see cref="Guid"/> example.</summary> |
| | | 32 | | /// <param name="example">The example value.</param> |
| | 0 | 33 | | public SwaggerSchemaExampleAttribute( Guid example ) => Example = example.ToString(); |
| | | 34 | | |
| | | 35 | | |
| | | 36 | | /// <summary>The example as text, as it appears in the OpenAPI document.</summary> |
| | | 37 | | public string Example { get; set; } |
| | | 38 | | } |