-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render Swagger UI links in a fancier, more useful way
- Loading branch information
1 parent
22a775b
commit 2a70642
Showing
7 changed files
with
155 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using Asp.Versioning.Conventions; | ||
using Asp.Versioning.OData; | ||
using Microsoft.AspNet.OData.Extensions; | ||
using Microsoft.Extensions.Primitives; | ||
using Microsoft.OData; | ||
using Newtonsoft.Json.Serialization; | ||
using Owin; | ||
|
@@ -131,25 +132,45 @@ public void Configuration( IAppBuilder builder ) | |
{ | ||
description.AppendLine(); | ||
|
||
var rendered = false; | ||
|
||
for ( var i = 0; i < policy.Links.Count; i++ ) | ||
{ | ||
var link = policy.Links[i]; | ||
|
||
if ( link.Type == "text/html" ) | ||
{ | ||
description.AppendLine(); | ||
|
||
if ( link.Title.HasValue ) | ||
if ( !rendered ) | ||
{ | ||
description.Append( link.Title.Value ).Append( ": " ); | ||
description.AppendLine(); | ||
description.Append( "**Links**" ); | ||
description.AppendLine(); | ||
rendered = true; | ||
} | ||
|
||
description.Append( link.LinkTarget.OriginalString ); | ||
if ( StringSegment.IsNullOrEmpty( link.Title ) ) | ||
{ | ||
if ( link.LinkTarget.IsAbsoluteUri ) | ||
{ | ||
description.AppendLine( $"- {link.LinkTarget.OriginalString}" ); | ||
} | ||
else | ||
{ | ||
description.AppendFormat( "- <a href=\"{0}\">{0}</a>", link.LinkTarget.OriginalString ); | ||
description.AppendLine(); | ||
} | ||
} | ||
else | ||
{ | ||
description.AppendLine( $"- [{link.Title}]({link.LinkTarget.OriginalString})" ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
description.AppendLine(); | ||
description.AppendLine( "**Additional Information**" ); | ||
info.Version( group.Name, $"Sample API {group.ApiVersion}" ) | ||
.Contact( c => c.Name( "Bill Mei" ).Email( "[email protected]" ) ) | ||
.Description( description.ToString() ) | ||
|
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using Asp.Versioning; | ||
using Asp.Versioning.Conventions; | ||
using Microsoft.AspNet.OData.Extensions; | ||
using Microsoft.Extensions.Primitives; | ||
using Microsoft.OData; | ||
using Newtonsoft.Json.Serialization; | ||
using Owin; | ||
|
@@ -105,25 +106,45 @@ public void Configuration( IAppBuilder builder ) | |
{ | ||
description.AppendLine(); | ||
|
||
var rendered = false; | ||
|
||
for ( var i = 0; i < policy.Links.Count; i++ ) | ||
{ | ||
var link = policy.Links[i]; | ||
|
||
if ( link.Type == "text/html" ) | ||
{ | ||
description.AppendLine(); | ||
|
||
if ( link.Title.HasValue ) | ||
if ( !rendered ) | ||
{ | ||
description.Append( link.Title.Value ).Append( ": " ); | ||
description.AppendLine(); | ||
description.Append( "**Links**" ); | ||
description.AppendLine(); | ||
rendered = true; | ||
} | ||
|
||
description.Append( link.LinkTarget.OriginalString ); | ||
if ( StringSegment.IsNullOrEmpty( link.Title ) ) | ||
{ | ||
if ( link.LinkTarget.IsAbsoluteUri ) | ||
{ | ||
description.AppendLine( $"- {link.LinkTarget.OriginalString}" ); | ||
} | ||
else | ||
{ | ||
description.AppendFormat( "- <a href=\"{0}\">{0}</a>", link.LinkTarget.OriginalString ); | ||
description.AppendLine(); | ||
} | ||
} | ||
else | ||
{ | ||
description.AppendLine( $"- [{link.Title}]({link.LinkTarget.OriginalString})" ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
description.AppendLine(); | ||
description.AppendLine( "**Additional Information**" ); | ||
info.Version( group.Name, $"Sample API {group.ApiVersion}" ) | ||
.Contact( c => c.Name( "Bill Mei" ).Email( "[email protected]" ) ) | ||
.Description( description.ToString() ) | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
using Asp.Versioning; | ||
using Asp.Versioning.Routing; | ||
using Microsoft.Extensions.Primitives; | ||
using Owin; | ||
using Swashbuckle.Application; | ||
using System.IO; | ||
|
@@ -10,6 +11,7 @@ | |
using System.Web.Http; | ||
using System.Web.Http.Description; | ||
using System.Web.Http.Routing; | ||
using static System.Net.Mime.MediaTypeNames; | ||
|
||
/// <summary> | ||
/// Represents the startup process for the application. | ||
|
@@ -88,25 +90,45 @@ public void Configuration( IAppBuilder builder ) | |
{ | ||
description.AppendLine(); | ||
|
||
var rendered = false; | ||
|
||
for ( var i = 0; i < policy.Links.Count; i++ ) | ||
{ | ||
var link = policy.Links[i]; | ||
|
||
if ( link.Type == "text/html" ) | ||
{ | ||
description.AppendLine(); | ||
|
||
if ( link.Title.HasValue ) | ||
if ( !rendered ) | ||
{ | ||
description.Append( link.Title.Value ).Append( ": " ); | ||
description.AppendLine(); | ||
description.Append( "**Links**" ); | ||
description.AppendLine(); | ||
rendered = true; | ||
} | ||
|
||
description.Append( link.LinkTarget.OriginalString ); | ||
if ( StringSegment.IsNullOrEmpty( link.Title ) ) | ||
{ | ||
if ( link.LinkTarget.IsAbsoluteUri ) | ||
{ | ||
description.AppendLine( $"- {link.LinkTarget.OriginalString}" ); | ||
} | ||
else | ||
{ | ||
description.AppendFormat( "- <a href=\"{0}\">{0}</a>", link.LinkTarget.OriginalString ); | ||
description.AppendLine(); | ||
} | ||
} | ||
else | ||
{ | ||
description.AppendLine( $"- [{link.Title}]({link.LinkTarget.OriginalString})" ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
description.AppendLine(); | ||
description.AppendLine( "**Additional Information**" ); | ||
info.Version( group.Name, $"Example API {group.ApiVersion}" ) | ||
.Contact( c => c.Name( "Bill Mei" ).Email( "[email protected]" ) ) | ||
.Description( description.ToString() ) | ||
|
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