| | | 1 | | namespace Kestrun.OpenApi; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents the fixed component buckets defined by the OpenAPI 3.2 specification |
| | | 5 | | /// under the <c>components</c> object. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <remarks> |
| | | 8 | | /// This enum mirrors the OpenAPI 3.2 Components Object exactly. |
| | | 9 | | /// It is intended for dispatch, existence checks, retrieval, and removal logic |
| | | 10 | | /// over <see cref="Microsoft.OpenApi.OpenApiComponents"/>. |
| | | 11 | | /// </remarks> |
| | | 12 | | public enum OpenApiComponentKind |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Reusable schema definitions for request and response payloads. |
| | | 16 | | /// Maps to <c>components/schemas</c>. |
| | | 17 | | /// </summary> |
| | | 18 | | Schemas, |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Reusable response definitions. |
| | | 22 | | /// Maps to <c>components/responses</c>. |
| | | 23 | | /// </summary> |
| | | 24 | | Responses, |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Reusable parameter definitions (query, header, path, cookie). |
| | | 28 | | /// Maps to <c>components/parameters</c>. |
| | | 29 | | /// </summary> |
| | | 30 | | Parameters, |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Reusable example definitions. |
| | | 34 | | /// Maps to <c>components/examples</c>. |
| | | 35 | | /// </summary> |
| | | 36 | | Examples, |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Reusable request body definitions. |
| | | 40 | | /// Maps to <c>components/requestBodies</c>. |
| | | 41 | | /// </summary> |
| | | 42 | | RequestBodies, |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Reusable header definitions. |
| | | 46 | | /// Maps to <c>components/headers</c>. |
| | | 47 | | /// </summary> |
| | | 48 | | Headers, |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Reusable security scheme definitions (OAuth2, API key, HTTP auth, etc.). |
| | | 52 | | /// Maps to <c>components/securitySchemes</c>. |
| | | 53 | | /// </summary> |
| | | 54 | | SecuritySchemes, |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Reusable link definitions describing relationships between operations. |
| | | 58 | | /// Maps to <c>components/links</c>. |
| | | 59 | | /// </summary> |
| | | 60 | | Links, |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Reusable callback definitions for asynchronous or event-driven APIs. |
| | | 64 | | /// Maps to <c>components/callbacks</c>. |
| | | 65 | | /// </summary> |
| | | 66 | | Callbacks, |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Reusable path item definitions. |
| | | 70 | | /// Maps to <c>components/pathItems</c>. |
| | | 71 | | /// </summary> |
| | | 72 | | PathItems, |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Reusable media type definitions (introduced in OpenAPI 3.2). |
| | | 76 | | /// Maps to <c>components/mediaTypes</c>. |
| | | 77 | | /// </summary> |
| | | 78 | | MediaTypes |
| | | 79 | | } |
| | | 80 | | /// <summary> |
| | | 81 | | /// Extension methods for <see cref="OpenApiComponentKind"/>. |
| | | 82 | | /// </summary> |
| | | 83 | | public static class OpenApiComponentKindExtensions |
| | | 84 | | { |
| | | 85 | | /// <summary> |
| | | 86 | | /// Converts the component kind to its inline label form. |
| | | 87 | | /// </summary> |
| | | 88 | | /// <param name="kind"> The kind of OpenAPI component.</param> |
| | | 89 | | /// <returns>The inline label corresponding to the component kind.</returns> |
| | 13 | 90 | | public static string ToInlineLabel(this OpenApiComponentKind kind) => kind switch |
| | 13 | 91 | | { |
| | 1 | 92 | | OpenApiComponentKind.Schemas => "schema", |
| | 1 | 93 | | OpenApiComponentKind.Responses => "response", |
| | 1 | 94 | | OpenApiComponentKind.Parameters => "parameter", |
| | 2 | 95 | | OpenApiComponentKind.Examples => "example", |
| | 1 | 96 | | OpenApiComponentKind.RequestBodies => "request body", |
| | 1 | 97 | | OpenApiComponentKind.Headers => "header", |
| | 1 | 98 | | OpenApiComponentKind.SecuritySchemes => "security scheme", |
| | 2 | 99 | | OpenApiComponentKind.Links => "link", |
| | 1 | 100 | | OpenApiComponentKind.Callbacks => "callback", |
| | 1 | 101 | | OpenApiComponentKind.PathItems => "path item", |
| | 1 | 102 | | OpenApiComponentKind.MediaTypes => "media type", |
| | 0 | 103 | | _ => kind.ToString() |
| | 13 | 104 | | }; |
| | | 105 | | /// <summary> |
| | | 106 | | /// Determines if the specified component kind supports inline definitions. |
| | | 107 | | /// </summary> |
| | | 108 | | /// <param name="kind">The kind of OpenAPI component.</param> |
| | | 109 | | /// <returns>True if the component kind supports inline definitions; otherwise, false.</returns> |
| | 11 | 110 | | public static bool SupportsInline(this OpenApiComponentKind kind) => kind switch |
| | 11 | 111 | | { |
| | 1 | 112 | | OpenApiComponentKind.Examples => true, |
| | 1 | 113 | | OpenApiComponentKind.Links => true, |
| | 1 | 114 | | OpenApiComponentKind.Parameters => true, |
| | 1 | 115 | | OpenApiComponentKind.Headers => true, |
| | 1 | 116 | | OpenApiComponentKind.MediaTypes => true, |
| | 6 | 117 | | _ => false |
| | 11 | 118 | | }; |
| | | 119 | | } |