From eb8bedb469f837c8943bd07b008117850ef60e48 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 23 May 2018 18:05:28 -0700 Subject: serve up swagger UI --- rust/src/bin/fatcatd.rs | 15 +++++++++++++-- rust/swagger-ui/index.html | 12 +++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs index f33c3763..19357c9e 100644 --- a/rust/src/bin/fatcatd.rs +++ b/rust/src/bin/fatcatd.rs @@ -17,7 +17,7 @@ extern crate slog_async; extern crate slog_term; use clap::{App, Arg}; -use iron::{Chain, Iron}; +use iron::{Chain, Iron, IronResult, Response, Request, status}; use iron_slog::{DefaultLogFormatter, LoggerMiddleware}; use slog::{Drain, Logger}; //use dotenv::dotenv; @@ -42,7 +42,18 @@ fn main() { let formatter = DefaultLogFormatter; let server = fatcat::server().unwrap(); - let router = fatcat_api::router(server); + let mut router = fatcat_api::router(server); + + router.get("/swagger-ui", swaggerui_handler, "swagger-ui-html"); + router.get("/v0/openapi2.yml", yaml_handler, "openapi2-spec-yaml"); + + fn swaggerui_handler(_: &mut Request) -> IronResult { + let html_type = "text/html".parse::().unwrap(); + Ok(Response::with((html_type, status::Ok, include_str!("../../swagger-ui/index.html")))) + } + fn yaml_handler(_: &mut Request) -> IronResult { + Ok(Response::with((status::Ok, include_str!("../../fatcat-openapi2.yml")))) + } let mut chain = Chain::new(LoggerMiddleware::new(router, logger, formatter)); diff --git a/rust/swagger-ui/index.html b/rust/swagger-ui/index.html index 7a45f1d5..14d3d48a 100644 --- a/rust/swagger-ui/index.html +++ b/rust/swagger-ui/index.html @@ -1,13 +1,15 @@ - + Swagger UI - + +