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
<!DOCTYPE html>
<html>
<head>
<title>API</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' />
<link href='css/reset-css' media='print' rel='stylesheet' type='text/css' />
public class ApplyBasicAuth : IOperationFilter
{
public string Name { get; private set; }
public ApplyBasicAuth()
{
Name = "basic";
}
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
@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 / index.html
Last active December 14, 2015 14:07
new inputs for swagger index.html
<div class="input"><input placeholder="username" id="input_username" name="username" type="text" size="10"></div>
<div class="input"><input placeholder="password" id="input_password" name="password" type="password" size="10"></div>
<Button id="loginbutton">Log in</Button>
public static class SwaggerExtensions
{
public static void ApplyBasicAuth(this SwaggerDocsConfig c)
{
var basicAuth = new ApplyBasicAuth();
basicAuth.Apply(c);
}
}
@VisualBean
VisualBean / SwaggerConfig.cs
Last active December 14, 2015 11:38
SwashBuckle config
c.BasicAuth("basic").Description("HTTP Authentication Method");
@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 / SwaggerConfig.cs
Last active March 18, 2016 13:08
Adding new basicauth to swaggerconfig
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
...
c.BasicAuth("basic").Description("HTTP Authentication Method");
c.OperationFilter<ApplyBasicAuth>();
...
});
@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();
}