using System; using System.IO; using System.Reflection; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace IGeekFan.AspNetCore.Knife4jUI { public class Knife4UIOptions { /// /// Gets or sets a route prefix for accessing the swagger-ui /// public string RoutePrefix { get; set; } = "swagger"; /// /// Gets or sets a Stream function for retrieving the swagger-ui page /// public Func IndexStream { get; set; } = () => typeof(Knife4UIOptions).GetTypeInfo().Assembly .GetManifestResourceStream("IGeekFan.AspNetCore.Knife4jUI.index.html"); /// /// Gets or sets a title for the swagger-ui page /// public string DocumentTitle { get; set; } = "Knife4j UI"; /// /// Gets or sets additional content to place in the head of the swagger-ui page /// public string HeadContent { get; set; } = ""; /// /// Gets the JavaScript config object, represented as JSON, that will be passed to the Knife4jUI /// public ConfigObject ConfigObject { get; set; } = new ConfigObject(); /// /// 暂不支持此特性Gets the JavaScript config object, represented as JSON, that will be passed to the initOAuth method /// [Obsolete] public OAuthConfigObject OAuthConfigObject { get; set; } = new OAuthConfigObject(); } public class ConfigObject { /// /// One or more Swagger JSON endpoints (url and name) to power the UI /// public IEnumerable Urls { get; set; } = null; /// /// If set to true, enables deep linking for tags and operations /// public bool DeepLinking { get; set; } = false; /// /// Controls the display of operationId in operations list /// public bool DisplayOperationId { get; set; } = false; /// /// The default expansion depth for models (set to -1 completely hide the models) /// public int DefaultModelsExpandDepth { get; set; } = 1; /// /// The default expansion depth for the model on the model-example section /// public int DefaultModelExpandDepth { get; set; } = 1; /// /// Controls how the model is shown when the API is first rendered. /// (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links) /// public ModelRendering DefaultModelRendering { get; set; } = ModelRendering.Example; /// /// Controls the display of the request duration (in milliseconds) for Try-It-Out requests /// public bool DisplayRequestDuration { get; set; } = false; /// /// Controls the default expansion setting for the operations and tags. /// It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing) /// public DocExpansion DocExpansion { get; set; } = DocExpansion.List; /// /// If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations /// that are shown. Can be an empty string or specific value, in which case filtering will be enabled using that /// value as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag /// public string Filter { get; set; } = null; /// /// If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations /// public int? MaxDisplayedTags { get; set; } = null; /// /// Controls the display of vendor extension (x-) fields and values for Operations, Parameters, and Schema /// public bool ShowExtensions { get; set; } = false; /// /// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters /// public bool ShowCommonExtensions { get; set; } = false; /// /// OAuth redirect URL /// [JsonPropertyName("oauth2RedirectUrl")] public string OAuth2RedirectUrl { get; set; } = null; /// /// List of HTTP methods that have the Try it out feature enabled. /// An empty array disables Try it out for all operations. This does not filter the operations from the display /// public IEnumerable SupportedSubmitMethods { get; set; } = Enum.GetValues(typeof(SubmitMethod)).Cast(); /// /// By default, Swagger-UI attempts to validate specs against swagger.io's online validator. /// You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). /// Setting it to null will disable validation /// public string ValidatorUrl { get; set; } = null; [JsonExtensionData] public Dictionary AdditionalItems { get; set; } = new Dictionary(); } public class UrlDescriptor { public string Url { get; set; } public string Name { get; set; } } public enum ModelRendering { Example, Model } public enum DocExpansion { List, Full, None } public enum SubmitMethod { Get, Put, Post, Delete, Options, Head, Patch, Trace } public class OAuthConfigObject { /// /// Default clientId /// public string ClientId { get; set; } = null; /// /// Default clientSecret /// public string ClientSecret { get; set; } = null; /// /// Realm query parameter (for oauth1) added to authorizationUrl and tokenUrl /// public string Realm { get; set; } = null; /// /// Application name, displayed in authorization popup /// public string AppName { get; set; } = null; /// /// Scope separator for passing scopes, encoded before calling, default value is a space (encoded value %20) /// public string ScopeSeparator { get; set; } = " "; /// /// Additional query parameters added to authorizationUrl and tokenUrl /// public Dictionary AdditionalQueryStringParams { get; set; } = null; /// /// Only activated for the accessCode flow. During the authorization_code request to the tokenUrl, /// pass the Client Password using the HTTP Basic Authentication scheme /// (Authorization header with Basic base64encode(client_id + client_secret)) /// public bool UseBasicAuthenticationWithAccessCodeGrant { get; set; } = false; /// /// Only applies to authorizatonCode flows. Proof Key for Code Exchange brings enhanced security for OAuth public clients. /// The default is false /// public bool UsePkceWithAuthorizationCodeGrant { get; set; } = false; } }