Skip to content

Commit

Permalink
Update to v0.3.0 (#9)
Browse files Browse the repository at this point in the history
- Added new default styles
- Introduced modern styles
  • Loading branch information
teociaps committed Feb 22, 2024
2 parents b054557 + d8128e8 commit f90cd53
Show file tree
Hide file tree
Showing 17 changed files with 1,547 additions and 56 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@

## Features

- **New Themes:** Enhances the Swagger documentation interface with a modern themes, including dark theme.
Currently, only the _Dark_ style is available; additional styles will be introduced in the future.
- **Seamless Integration:** Simply install the package and add the style parameter to the existing method used for SwaggerUI.
- _New Themes_: enhances the Swagger documentation interface with different themes, including a default style that retains the classic Swagger UI appearance and new modern styles.
- _Seamless Integration_: simply install the package and add the style parameter to the existing method used for SwaggerUI.

## Themes

There are a few themes available for your Swagger UI:

### Default Styles

- __Dark__: offers a simple dark-themed interface, maintaining the classic Swagger UI layout;
- __Forest__: inspired by the colors of a forest, this theme brings a natural and vibrant feel to your documentation;
- __DeepSea__: inspired by the depths of the sea, this theme features cool blues and deep greens for a tranquil and immersive experience.

> The light style is not in this list because it's just the default one used by Swagger UI; to use that you don't need this library.
### Modern Styles

- __Light__: offers a modern, light-themed interface that overrides some aspects of the default Swagger UI;
- __Dark__: provides a sleek, dark-themed interface for a more modern look and feel.

## Supported .NET Versions

Expand All @@ -52,7 +67,7 @@ The table below provides a quick overview of **AspNetCore.SwaggerUI.Themes** ver
| Library Version | .NET 6 | .NET 7 | .NET 8 |
| --------------- | ------ | ------ | ------ |
| 0.1.0 ||||
| 0.2.0 ||||
| 0.2.0 + ||||

- ✔️ Supported: The library version is compatible with the respective .NET version.
- ❌ Unsupported: The library version is not compatible with the respective .NET version.
Expand All @@ -74,7 +89,7 @@ To use **AspNetCore.SwaggerUI.Themes** in your ASP.NET Core project, follow thes
Install-Package AspNetCore.SwaggerUI.Themes
```

2. In your `Program.cs` file, add the style through the `Style` class as new parameter of `app.UseSwaggerUI()` method:
2. In your `Program.cs` file, add the style through the `Style` or `ModernStyle` class as new parameter of `app.UseSwaggerUI()` method:

```csharp
using AspNetCore.SwaggerUI.Themes;
Expand Down Expand Up @@ -105,7 +120,7 @@ builder.Services.AddSwaggerGen();
app.UseSwagger();

// Enable the dark theme for Swagger UI
app.UseSwaggerUI(Style.Dark, c =>
app.UseSwaggerUI(ModernStyle.Dark, c =>
{
// Your Swagger UI configuration here (optional)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public IActionResult OptionsSample()
return Ok();
}

[HttpPost("form")]
[Authorize]
public IActionResult PostSample([FromForm] Sample model, IFormFile form)

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'

Check warning on line 35 in samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Controllers/SampleController.cs

View workflow job for this annotation

GitHub Actions / build

'Sample' is obsolete: 'test'
{
return Ok();
}

[HttpGet("get")]
[Obsolete("test")]
public IActionResult GetDisabledSample([Required] int sample)
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample.AspNetCore.SwaggerUI.Swashbuckle/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(Style.Dark, c => c.DocumentTitle = "Sample Title");
app.UseSwaggerUI(ModernStyle.Dark, c => c.DocumentTitle = "Sample Title");
}

app.UseHttpsRedirection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Official Version -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<MajorVersion>0</MajorVersion>
<MinorVersion>2</MinorVersion>
<MinorVersion>3</MinorVersion>
<PatchVersion>0</PatchVersion>
<VersionSuffix></VersionSuffix> <!-- used for preview -->
<Version>$(MajorVersion).$(MinorVersion).$(PatchVersion)$(VersionSuffix)</Version>
Expand All @@ -25,6 +25,11 @@
<ItemGroup>
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\common.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\dark.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\deepsea.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\forest.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\modern.light.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\modern.common.css" />
<EmbeddedResource Include="AspNetCore\SwaggerUI\Themes\Styles\modern.dark.css" />
</ItemGroup>

<ItemGroup>
Expand Down
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
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,26 @@
/// <summary>
/// Represents a style for Swagger UI.
/// </summary>
public sealed class Style
public sealed class Style : BaseStyle
{
private Style(string fileName)
private Style(string fileName) : base(fileName)
{
CheckFileNameExtension(fileName);
FileName = fileName;
}

/// <summary>
/// Gets the file name associated with the selected style.
/// </summary>
public string FileName { get; }
internal override Style Common => new("common.css");

/// <summary>
/// Apply a dark style to your Swagger UI.
/// </summary>
public static Style Dark => new("dark.css");

internal static Style Common => new("common.css");

// TODO: custom style

// TODO: default and modern styles

/// <summary>
/// Returns the file name and format as a string representation of the style.
/// Apply a forest tones style to your Swagger UI.
/// </summary>
/// <returns>The file name and format associated with the style.</returns>
public override string ToString() => $"{GetStyleName()} Style";
public static Style Forest => new("forest.css");

/// <summary>
/// Gets the name of the style without the file extension.
/// Apply a deep sea tones style to your Swagger UI.
/// </summary>
/// <returns>The style name.</returns>
public 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));
}
public static Style DeepSea => new("deepsea.css");
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ body {

/* Code highlighted one color (e.g. response headers) */
.swagger-ui .opblock-body pre.microlight {
background: var(--opblock-pre-microlight-background-color, #333);
color: var(--opblock-pre-microlight-color, #fff);
background: var(--opblock-pre-microlight-background-color, #333) !important;
color: var(--opblock-pre-microlight-color, #fff) !important;
}

/* Download & copy to clipboard button of a content */
Expand Down

0 comments on commit f90cd53

Please sign in to comment.