| | | 1 | | |
| | | 2 | | /// <summary> |
| | | 3 | | /// Rich OpenAPI schema metadata for a property or a class. |
| | | 4 | | /// Apply to: |
| | | 5 | | /// <list type="bullet"> |
| | | 6 | | /// <item><description>Class (object-level): set <see cref="RequiredProperties"/> array, XML hints, discriminator, etc.< |
| | | 7 | | /// <item><description>Property (member-level): set description, format, constraints, enum, etc.</description></item> |
| | | 8 | | /// </list> |
| | | 9 | | /// </summary> |
| | | 10 | | public abstract class OpenApiProperties : KestrunAnnotation |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Type of additionalProperties (if allowed). |
| | | 14 | | /// </summary> |
| | | 15 | | private Type? _additionalProperties; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Human-friendly title for the schema. |
| | | 19 | | /// </summary> |
| | 60 | 20 | | public string? Title { get; set; } |
| | | 21 | | /// <summary>Markdown-capable description.</summary> |
| | 246 | 22 | | public string? Description { get; set; } |
| | | 23 | | |
| | | 24 | | /// <summary>Explicit OpenAPI type override (otherwise inferred).</summary> |
| | 72 | 25 | | public OaSchemaType Type { get; set; } = OaSchemaType.None; |
| | 52 | 26 | | public string? Format { get; set; } |
| | | 27 | | /// <summary>Default value.</summary> |
| | 52 | 28 | | public object? Default { get; set; } |
| | | 29 | | /// <summary>Example value (single example).</summary> |
| | 54 | 30 | | public object? Example { get; set; } |
| | | 31 | | /// <summary>Marks the schema as nullable (OAS 3.0).</summary> |
| | 52 | 32 | | public bool Nullable { get; set; } |
| | | 33 | | /// <summary>Indicates the value is read-only (responses only).</summary> |
| | 52 | 34 | | public bool ReadOnly { get; set; } |
| | | 35 | | /// <summary>Indicates the value is write-only (requests only).</summary> |
| | 52 | 36 | | public bool WriteOnly { get; set; } |
| | | 37 | | /// <summary>Marks the schema/property as deprecated.</summary> |
| | 50 | 38 | | public bool Deprecated { get; set; } |
| | | 39 | | /// <summary> |
| | | 40 | | /// Indicates the property is an array (enables array constraints). |
| | | 41 | | /// </summary> |
| | 16 | 42 | | public bool Array { get; set; } |
| | | 43 | | // ---- Numbers ---- |
| | | 44 | | /// <summary>Value must be a multiple of this.</summary> |
| | 52 | 45 | | public decimal? MultipleOf { get; set; } |
| | | 46 | | /// <summary>Inclusive maximum.</summary> |
| | 52 | 47 | | public string? Maximum { get; set; } |
| | | 48 | | /// <summary>Exclusive maximum flag.</summary> |
| | 0 | 49 | | public bool ExclusiveMaximum { get; set; } |
| | | 50 | | /// <summary>Inclusive minimum.</summary> |
| | 52 | 51 | | public string? Minimum { get; set; } |
| | | 52 | | /// <summary>Exclusive minimum flag.</summary> |
| | 0 | 53 | | public bool ExclusiveMinimum { get; set; } |
| | | 54 | | |
| | | 55 | | // ---- Strings ---- |
| | | 56 | | /// <summary>Maximum length (characters).</summary> |
| | 347 | 57 | | public int MaxLength { get; set; } = -1; |
| | | 58 | | /// <summary>Minimum length (characters).</summary> |
| | 347 | 59 | | public int MinLength { get; set; } = -1; |
| | | 60 | | /// <summary>ECMA-262 compliant regex.</summary> |
| | 52 | 61 | | public string? Pattern { get; set; } |
| | | 62 | | |
| | | 63 | | // ---- Arrays ---- |
| | | 64 | | /// <summary>Max items in array.</summary> |
| | 347 | 65 | | public int MaxItems { get; set; } = -1; |
| | | 66 | | /// <summary>Min items in array.</summary> |
| | 347 | 67 | | public int MinItems { get; set; } = -1; |
| | | 68 | | /// <summary>Items must be unique.</summary> |
| | 52 | 69 | | public bool UniqueItems { get; set; } |
| | | 70 | | |
| | | 71 | | // ---- Objects ---- |
| | | 72 | | /// <summary>Max properties an object may contain.</summary> |
| | 347 | 73 | | public int MaxProperties { get; set; } = -1; |
| | | 74 | | /// <summary>Min properties an object must contain.</summary> |
| | 347 | 75 | | public int MinProperties { get; set; } = -1; |
| | | 76 | | |
| | | 77 | | /// <summary> |
| | | 78 | | /// Object-level required property names (apply this on the CLASS). |
| | | 79 | | /// </summary> |
| | 65 | 80 | | public string[]? RequiredProperties { get; set; } |
| | | 81 | | |
| | | 82 | | // ---- Enum ---- |
| | | 83 | | /// <summary>Allowed constant values for the schema.</summary> |
| | 52 | 84 | | public object[]? Enum { get; set; } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Schema type by .NET type for code-first generators. |
| | | 88 | | /// </summary> |
| | 33 | 89 | | public Type? SchemaType { get; set; } |
| | | 90 | | |
| | | 91 | | // ---- Array typing ---- |
| | | 92 | | /// <summary>Items type by OpenAPI reference (e.g., "#/components/schemas/Address").</summary> |
| | | 93 | | /// <summary>Items type by .NET type for code-first generators.</summary> |
| | 1 | 94 | | public Type? ItemsType { get; set; } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Indicates whether additionalProperties are allowed (default: false). |
| | | 98 | | /// </summary> |
| | 674 | 99 | | public bool AdditionalPropertiesAllowed { get; set; } = true; |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Type of additionalProperties (if allowed). |
| | | 103 | | /// </summary> |
| | | 104 | | /// <remarks>Set AdditionalPropertiesAllowed to true if this is set.</remarks> |
| | | 105 | | public Type? AdditionalProperties |
| | | 106 | | { |
| | 33 | 107 | | get => _additionalProperties; |
| | | 108 | | set |
| | | 109 | | { |
| | 25 | 110 | | _additionalProperties = value; |
| | 25 | 111 | | if (value != null) |
| | | 112 | | { |
| | 25 | 113 | | AdditionalPropertiesAllowed = true; |
| | | 114 | | } |
| | 25 | 115 | | } |
| | | 116 | | } |
| | | 117 | | |
| | | 118 | | // ---- Composition ---- |
| | | 119 | | /// <summary>oneOf refs (by $ref).</summary> |
| | 0 | 120 | | public string[]? OneOfRefs { get; set; } |
| | | 121 | | /// <summary>anyOf refs (by $ref).</summary> |
| | 0 | 122 | | public string[]? AnyOfRefs { get; set; } |
| | | 123 | | /// <summary>allOf refs (by $ref).</summary> |
| | 0 | 124 | | public string[]? AllOfRefs { get; set; } |
| | | 125 | | /// <summary>not ref (by $ref).</summary> |
| | 0 | 126 | | public string? NotRef { get; set; } |
| | | 127 | | /// <summary>oneOf types (by .NET type).</summary> |
| | 0 | 128 | | public Type[]? OneOfTypes { get; set; } |
| | | 129 | | /// <summary>anyOf types (by .NET type).</summary> |
| | 0 | 130 | | public Type[]? AnyOfTypes { get; set; } |
| | | 131 | | /// <summary>allOf types (by .NET type).</summary> |
| | 0 | 132 | | public Type[]? AllOfTypes { get; set; } |
| | | 133 | | /// <summary>not type (by .NET type).</summary> |
| | 0 | 134 | | public Type? NotType { get; set; } |
| | | 135 | | |
| | | 136 | | // ---- Discriminator ---- |
| | | 137 | | /// <summary>Name of the property used to discriminate between schemas.</summary> |
| | 0 | 138 | | public string? DiscriminatorPropertyName { get; set; } |
| | | 139 | | /// <summary>Payload values matched by the discriminator.</summary> |
| | 0 | 140 | | public string[]? DiscriminatorMappingKeys { get; set; } |
| | | 141 | | /// <summary>Schema $refs that correspond to the mapping keys.</summary> |
| | 0 | 142 | | public string[]? DiscriminatorMappingRefs { get; set; } |
| | | 143 | | |
| | | 144 | | // ---- External Docs ---- |
| | | 145 | | /// <summary>External documentation URL.</summary> |
| | 0 | 146 | | public string? ExternalDocsUrl { get; set; } |
| | | 147 | | /// <summary>Description for the external docs.</summary> |
| | 0 | 148 | | public string? ExternalDocsDescription { get; set; } |
| | | 149 | | |
| | | 150 | | // ---- XML ---- |
| | | 151 | | /// <summary>XML element/attribute name.</summary> |
| | 64 | 152 | | public string? XmlName { get; set; } |
| | | 153 | | /// <summary>XML namespace.</summary> |
| | 62 | 154 | | public string? XmlNamespace { get; set; } |
| | | 155 | | /// <summary>XML prefix.</summary> |
| | 58 | 156 | | public string? XmlPrefix { get; set; } |
| | | 157 | | /// <summary>Indicates the property is an XML attribute.</summary> |
| | 57 | 158 | | public bool XmlAttribute { get; set; } |
| | | 159 | | /// <summary>Indicates arrays are wrapped in an enclosing element.</summary> |
| | 54 | 160 | | public bool XmlWrapped { get; set; } |
| | | 161 | | /// <summary> |
| | | 162 | | /// Sets unevaluatedProperties for OpenAPI Schema (null = generator decides). |
| | | 163 | | /// </summary> |
| | 52 | 164 | | public bool UnevaluatedProperties { get; set; } |
| | | 165 | | } |