nancy-metadata-swagger - Nancy.Metadata.Swagger.Core 0.4.0
This is a port of the Nancy.Metadata.Swagger that works for newer Nancy versions
PM> Install-Package Nancy.Metadata.Swagger.Core -Version 0.4.0 -Source https://www.myget.org/F/nancy-metadata-swagger/api/v3/index.json
> nuget.exe install Nancy.Metadata.Swagger.Core -Version 0.4.0 -Source https://www.myget.org/F/nancy-metadata-swagger/api/v3/index.json
> dotnet add package Nancy.Metadata.Swagger.Core --version 0.4.0 --source https://www.myget.org/F/nancy-metadata-swagger/api/v3/index.json
source https://www.myget.org/F/nancy-metadata-swagger/api/v3/index.json
nuget Nancy.Metadata.Swagger.Core ~> 0.4.0
Copy to clipboard
> choco install Nancy.Metadata.Swagger.Core --version 0.4.0 --source https://www.myget.org/F/nancy-metadata-swagger/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "nancy-metadata-swagger" -SourceLocation "https://www.myget.org/F/nancy-metadata-swagger/api/v2"
Install-Module -Name "Nancy.Metadata.Swagger.Core" -RequiredVersion "0.4.0" -Repository "nancy-metadata-swagger"
Copy to clipboard
Nancy.Metadata.Swagger.Core
This is a port of the existing Nancy.Metadata.Swagger repository but updated to target the latest version of NancyFx and also targeting NetStandard 2.0. Most of the modifications have been minor tweaks and havent really affected the surface of the API in order to maintain backwards compatibility when targeting Nancy 1.+ and 2.+.
Note: Since Nancyfx is no longer being maintained i will be deprioritizing this library, please check here for details
Introduction
Nancy.Metadata.Swagger is a library that makes it easier to create API documentation for swagger 2.0 with Nancy metadata modules. This targets exclusively the 2.0 Swagger specification. For an updated version that targets OpenApi 3.0.0, check the following library.
Dependencies
Nancy.Metadata.Swagger uses Newtonsoft Json.Net and NJsonSchema for .Net to generate the object schema structure. Also it uses some of Nancy libraries, so those will be installed as well as part of the dependencies.
Gettings started
Install Nancy.Metadata.Swagger.Core via nuget packages:
PM> Install-Package Nancy.Metadata.Swagger.Core
You will also need the Nancy.Metadata.Modules
package from nuget:
PM> Install-Package Nancy.Metadata.Modules
Once this is done, locate your module implementations and generate a MetadataModule with the descriptions.
This is a sample implementation of a Nancy Module:
public class RootModule : NancyModule
{
public RootModule() : base("/api")
{
Get["SimpleRequestWithParameter", "/hello/{name}"] = r => Hello(r.name);
}
}
The example metadata module (for %modulename%Module
should be named %modulename%MetadataModule
):
public class RootMetadataModule : MetadataModule<SwaggerRouteMetadata>
{
public RootMetadataModule()
{
Describe["SimpleRequestWithParameter"] = desc => new SwaggerRouteMetadata(desc)
.With(i => i.WithResponseModel("200", typeof(SimpleResponseModel), "Sample response")
.WithRequestParameter("name"));
}
}
** !IMPORTANT: Metadata module class should be placed at the same namespace within the module for discovering purposes**
After doing this for each module desired, configure the endpoint that will serve the documents described.
Adding the docs module
This module will return your json documentation. The key is the inheritance from SwaggerDocsModuleBase.
Here's a sample module:
public class DocsModule : SwaggerDocsModuleBase
{
public DocsModule(IRouteCacheProvider routeCacheProvider)
: base(routeCacheProvider,
"/api/docs", // where module should be located
"Sample API documentation", // title
"v1.0", // api version
"localhost:5000", // host
"/api", // api base url (ie /dev, /api)
"http") // schemes
{
}
}
Default values are provided, but it is encouraged that you configure your own values, obtaining them from config files or environment vars (see the sample).
Adding swagger UI
This is completely optional and its mostly for discovery purposes. It is feasible to add Swagger-UI (you can download it from swagger-ui or check the github repository here or heck, use npm) and point it to your document module. At the index.html file you can set the default url where swagger-ui should get the json documentation file. For more details check the sample application.
Missing Swagger features
Since Swagger's latest standard is for OpenApi (Version 3.+), i would not be putting any type of effort into adding enhancements to this library, since the functionality mostly covers my current needs. I will take care of bumps to the release version of netcore for Nancy, Swagger-UI and any bugs found. By all means, Feel free to Clone and PR away if you would like to add any new features.
Expanded library to target to nancy 1.x for .Net Framework
-
.NETFramework 4.5.2
- Nancy (>= 1.4.5)
- Nancy.Metadata.Modules (>= 1.4.1)
- Newtonsoft.Json (>= 12.0.3)
- NJsonSchema (>= 10.1.12)
-
.NETStandard 2.0
- Nancy (>= 2.0.0)
- Nancy.Metadata.Modules (>= 2.0.0)
- Newtonsoft.Json (>= 12.0.3)
- NJsonSchema (>= 10.1.12)
- .NETFramework 4.5.2: 4.5.2.0
- .NETStandard 2.0: 2.0.0.0
OwnersJaxelr |
AuthorsJaxel Rojas, Anton Kudryavtsev |
Project URLhttps://github.com/Jaxelr/Nancy.Metadata.Swagger.Core |
LicenseMIT |
Tagsnancyfx swagger |
Info11 total downloads |
1 downloads for version 0.4.0 |
Download (25.79 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
0.4.0 | 25.79 KB | Sun, 29 Mar 2020 04:06:49 GMT | 1 | ||||
0.3.4 | 25.82 KB | Mon, 09 Dec 2019 21:58:04 GMT | 1 | ||||
0.3.3 | 18.63 KB | Wed, 16 Oct 2019 00:27:41 GMT | 1 | ||||
0.3.2 | 18.62 KB | Tue, 23 Jul 2019 10:48:00 GMT | 1 | ||||
0.3.1 | 19.27 KB | Mon, 03 Jun 2019 21:31:35 GMT | 3 | ||||
0.3.0 | 19.39 KB | Thu, 23 May 2019 10:14:20 GMT | 2 | ||||
0.2.0 | 18.72 KB | Mon, 29 Apr 2019 14:41:07 GMT | 1 | ||||
0.1.2 | 18.8 KB | Wed, 18 Jul 2018 10:14:18 GMT | 0 | ||||
0.1.1 | 10.65 KB | Wed, 02 May 2018 17:51:58 GMT | 1 |