-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added new default styles - Introduced modern styles
- Loading branch information
Showing
17 changed files
with
1,547 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/AspNetCore.SwaggerUI.Themes/AspNetCore/SwaggerUI/Themes/BaseStyle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace AspNetCore.SwaggerUI.Themes; | ||
|
||
/// <summary> | ||
/// Represents the base class used to create a style for Swagger UI. | ||
/// </summary> | ||
public abstract class BaseStyle | ||
{ | ||
private protected BaseStyle(string fileName) | ||
{ | ||
CheckFileNameExtension(fileName); | ||
FileName = fileName; | ||
} | ||
|
||
internal virtual BaseStyle Common { get; } | ||
|
||
/// <summary> | ||
/// Gets the file name associated with the selected style. | ||
/// </summary> | ||
public string FileName { get; } | ||
|
||
/// <summary> | ||
/// Returns the file name as a string representation of the style. | ||
/// </summary> | ||
/// <returns>The file name associated with the style.</returns> | ||
public override string ToString() => $"{GetStyleName()} Style"; | ||
|
||
/// <summary> | ||
/// Gets the name of the style without the file extension. | ||
/// </summary> | ||
/// <returns>The style name.</returns> | ||
protected virtual string GetStyleName() | ||
{ | ||
#if NET6_0_OR_GREATER | ||
return char.ToUpper(FileName[0]) + FileName[1..(FileName.LastIndexOf('.'))]; | ||
#else | ||
return char.ToUpper(FileName[0]) + FileName.Substring(1, FileName.LastIndexOf('.')); | ||
#endif | ||
} | ||
|
||
private static void CheckFileNameExtension(string fileName) | ||
{ | ||
if (!fileName.EndsWith(".css", StringComparison.OrdinalIgnoreCase)) | ||
throw new ArgumentException("The file name extension doesn't match the CSS style format!", nameof(fileName)); | ||
} | ||
} | ||
|
||
// TODO: custom style |
33 changes: 33 additions & 0 deletions
33
src/AspNetCore.SwaggerUI.Themes/AspNetCore/SwaggerUI/Themes/ModernStyle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace AspNetCore.SwaggerUI.Themes; | ||
|
||
/// <summary> | ||
/// Represents a modern style for Swagger UI. | ||
/// </summary> | ||
public sealed class ModernStyle : BaseStyle | ||
{ | ||
private ModernStyle(string fileName) : base(fileName) | ||
{ | ||
} | ||
|
||
internal override ModernStyle Common => new("modern.common.css"); | ||
|
||
/// <summary> | ||
/// Apply a modern light style to your Swagger UI. | ||
/// </summary> | ||
public static ModernStyle Light => new("modern.light.css"); | ||
|
||
/// <summary> | ||
/// Apply a modern sleek dark style to your Swagger UI. | ||
/// </summary> | ||
public static ModernStyle Dark => new("modern.dark.css"); | ||
|
||
/// <inheritdoc/> | ||
protected override string GetStyleName() | ||
{ | ||
#if NET6_0_OR_GREATER | ||
return char.ToUpper(FileName[0]) + FileName[1..(FileName.LastIndexOf('.'))].Replace('.', ' '); | ||
#else | ||
return char.ToUpper(FileName[0]) + FileName.Substring(1, FileName.LastIndexOf('.')).Replace('.', ' '); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.