Skip to content

Instantly share code, notes, and snippets.

View VisualBean's full-sized avatar
🐵

Alex Wichmann VisualBean

🐵
View GitHub Profile
@VisualBean
VisualBean / TreeFromFlatList.txt
Last active November 30, 2015 13:56
Creating a tree from a flat list of "Organizations"
parents.foreach(p => p.childs = parents.Where(pa => pa.ParentId == p.Id));
return parents.Where(p => p.Id == null); //Returns the very top of the tree
public static class SwaggerExtensions
{
public static void ApplyBasicAuth(this SwaggerDocsConfig c)
{
var basicAuth = new ApplyBasicAuth();
basicAuth.Apply(c);
}
}
@VisualBean
VisualBean / Index.html
Created December 14, 2015 10:52
Original Swagger Index file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
@VisualBean
VisualBean / BooksController.cs
Created December 14, 2015 11:34
A Very simple example of manual pagination
[HttpGet]
public IHttpResult Books(int page = 1, int pageSize = 20)
{
List<Book> books = BooksRepository.AllBooks();
return books.Take(pageSize).Skip((page-1)*pageSize).ToList();
}
@VisualBean
VisualBean / BasicAuth.js
Last active December 14, 2015 11:37
Basic-Authentication for swaggers index.html
function addBasicAuthorization() {
var username = $('#input_username').val();
var password = $('#input_password').val();
if (username && username.trim() != "" && password && password.trim() != "") {
var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
window.swaggerUi.api.clientAuthorizations.add("basicAuth", basicAuth);
}
}
@VisualBean
VisualBean / SwaggerConfig.cs
Last active December 14, 2015 11:38
SwashBuckle config
c.BasicAuth("basic").Description("HTTP Authentication Method");
@VisualBean
VisualBean / PagingFilter.cs
Created December 14, 2015 11:38
partial part of pagingFilter.cs
var queryString = HttpUtility.ParseQueryString(context.Request.RequestUri.Query);
var brandName = queryString.Get("brand");
@VisualBean
VisualBean / PagingFilter.cs
Last active December 14, 2015 11:39
Partial bit of PaginFilter.cs
int offset = 0;
int limit = 0;
var queryString = HttpUtility.ParseQueryString(context.Request.RequestUri.Query);
if(queryString.Count == 0) return;
int.TryParse(queryString.Get("offset"), out offset);
int.TryParse(queryString.Get("limit"), out limit);
@VisualBean
VisualBean / PagingFilter.cs
Created December 14, 2015 11:40
Partial part of PagingFilter.cs
var objectContent = context.ActionContext?.Response?.Content as ObjectContent;
if (objectContent != null)
objectContent.Value = result;
@VisualBean
VisualBean / PagingFilter.cs
Created December 14, 2015 11:41
Partial Part of PagingFilter.cs
public class PagingFilter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext context)
{
}
}