Permalink
Browse files

ReadMe

  • Loading branch information...
1 parent 1632355 commit 66c2c622d2fda746fe78b8743b6a270aea353333 @neuecc committed Apr 19, 2015
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -46,7 +46,7 @@ public class My : LightNodeContract
Compile, run, very quick! LightNode calls class as Contract, method as Operation.
-> Parameter model bindings supports only basic pattern, can't use complex type. allow types are "string, DateTime, DateTimeOffset, Boolean, Decimal, Char, TimeSpan, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, SByte, Byte and each Nullable types and array(except byte[]. If you want to use byte[], use Base64 string instead of byte[] or see [receive byte[] section](#receiveor-send-byte))
+> Parameter model bindings supports only basic pattern, can't use complex type. allow types are "string, DateTime, DateTimeOffset, Boolean, Decimal, Char, TimeSpan, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, SByte, Byte, Enum and each Nullable types and array(except byte[]. If you want to use byte[], use Base64 string instead of byte[] or see [receive byte[] section](#receiveor-send-byte))
> Return type allows all serializable(ContentFormatter support) type.
@@ -166,6 +166,61 @@ req.CookieContainer.Add(new Uri("http://localhost:41932"), new Cookie("glimpseid
```
![](Img/glimpse_history_clientgrouping.jpg)
+Swagger Integration
+---
+LightNode supports [Swagger](http://swagger.io/) for API Explorer(currently Swagger supports is experimental, only shows parameters).
+
+![](Img/swagger_support.jpg)
+
+Middleware available in NuGet.
+
+* PM> Install-Package [LightNode.Swagger](https://nuget.org/packages/LightNode.Swagger/)
+
+Swagger-UI file is embedded in LightNode.Swagger. You can enable only `UseLightNodeSwagger`.
+
+```csharp
+// Currently LightNode.Swagger only supports POST so you needs AcceptVerbs.Post
+app.Map("/api", builder =>
+{
+ builder.UseLightNode(new LightNodeOptions(AcceptVerbs.Get | AcceptVerbs.Post, new JilContentFormatter(), new GZipJilContentFormatter())
+ {
+ ParameterEnumAllowsFieldNameParse = true, // If you want to use enums human readable display on Swagger, set to true
+ ErrorHandlingPolicy = ErrorHandlingPolicy.ReturnInternalServerErrorIncludeErrorDetails,
+ OperationMissingHandlingPolicy = OperationMissingHandlingPolicy.ReturnErrorStatusCodeIncludeErrorDetails
+ });
+});
+
+// Mapping to swagger path
+app.Map("/swagger", builder =>
+{
+ // If you want to additional info for Swagger, load xmlDoc file.
+ // LightNode.Swagger loads methods's summary, remarks, param for info.
+ var xmlName = "LightNode.Sample.GlimpseUse.xml";
+ var xmlPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\bin\\" + xmlName; // or HttpContext.Current.Server.MapPath("~/bin/" + xmlName);
+
+ builder.UseLightNodeSwagger(new Swagger.SwaggerOptions("LightNodeSample", "/api") // baseApi is LightNode's root
+ {
+ XmlDocumentPath = xmlPath,
+ IsEmitEnumAsString = true
+ });
+});
+```
+
+Okay, for example jump to `http://localhost:41932/Swagger/`, you can see all API info and Swagger specification json can download from `api-default.json`. If you host multiple LightNode engine, you can select target engine from `{engineID}.json`. `{engineID}` is from `ILightNodeOptions.ServerEngineId`.
+
+If you can't run swagger on hosting IIS, maybe conflicts static file handling. Please remoe StaticFile handler and register OwinHttpHandler for all paths.
+
+```csharp
+<system.webServer>
+ <handlers>
+ <remove name="StaticFile" />
+ <!-- If use with Glimpse, glimpse handler must be first -->
+ <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
+ <add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />
+ </handlers>
+</system.webServer>
+```
+
with ASP.NET MVC
---
You can use LightNode with ASP.NET MVC. A simple solution is to change the root path.
@@ -374,6 +429,12 @@ LightNode is using [AppVeyor](http://www.appveyor.com/) CI. You can check unit t
ReleaseNote
---
+1.2.0 - 2015-04-19
+* Add LightNode.Swagger
+* Add LightNodeServerMiddleware.GetRegisteredHandlersInfo
+* Changed JilContentFormatter namespace
+* Fix UniRx.T4 LightNodeClient
+
1.1.0 - 2015-02-21
* Add AcceptVerbs.Put/Delete/Patch
* Add HttpVerbAttributes([GET/POST/Put/Delete/Patch]Attribute)
@@ -2,7 +2,6 @@
using Glimpse.CloudStructures.Redis;
using Glimpse.LightNode;
using LightNode.Formatter;
-using LightNode.Formatter.Jil;
using LightNode.Server;
using Microsoft.Owin;
using Owin;
@@ -98,12 +97,12 @@ public enum JapaneseFruit
public class Member : LightNodeContract
{
/// <summary>
- /// My Random...
+ /// Generate Random Person
/// </summary>
- /// <remarks>Remarks</remarks>
- /// <param name="seed">see.ee.d</param>
- /// <returns>result</returns>
- public async Task<Person> Random(int seed)
+ /// <remarks>This area is generated from Xml doc-comment remarks.</remarks>
+ /// <param name="seed">Random seed.</param>
+ /// <param name="fruit">Suports enum.</param>
+ public async Task<Person> Random(int seed, Fruit fruit = Fruit.Banana)
{
//await Redis.Settings.String<string>("Person?Seed=" + seed).Get();
var rand = new Random(seed);
@@ -280,7 +280,10 @@ static string TypeToType(Type type)
var summary = ((string)x.Element("summary")) ?? "";
var returns = ((string)x.Element("returns")) ?? "";
var remarks = ((string)x.Element("remarks")) ?? "";
- var parameters = x.Elements("param").ToDictionary(e => e.Attribute("name").Value, e => e.Value);
+ var parameters = x.Elements("param")
+ .Select(e => Tuple.Create(e.Attribute("name").Value, e))
+ .Distinct(new Item1EqualityCompaerer<string, XElement>())
+ .ToDictionary(e => e.Item1, e => e.Item2.Value);
return new XmlCommentStructure
{
@@ -297,6 +300,19 @@ static string TypeToType(Type type)
return xDocLookup;
}
+ class Item1EqualityCompaerer<T1, T2> : EqualityComparer<Tuple<T1, T2>>
+ {
+ public override bool Equals(Tuple<T1, T2> x, Tuple<T1, T2> y)
+ {
+ return x.Item1.Equals(y.Item1);
+ }
+
+ public override int GetHashCode(Tuple<T1, T2> obj)
+ {
+ return obj.Item1.GetHashCode();
+ }
+ }
+
class XmlCommentStructure
{
public string ClassName { get; set; }

0 comments on commit 66c2c62

Please sign in to comment.