diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-23 18:05:28 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-24 15:21:32 -0700 |
commit | eb8bedb469f837c8943bd07b008117850ef60e48 (patch) | |
tree | cd12c9133c2f2bcb4963a90ee90d12512faff708 | |
parent | 4ffd65c7ed400a5762f8b5e25f23f6815685c6d8 (diff) | |
download | fatcat-eb8bedb469f837c8943bd07b008117850ef60e48.tar.gz fatcat-eb8bedb469f837c8943bd07b008117850ef60e48.zip |
serve up swagger UI
-rw-r--r-- | rust/src/bin/fatcatd.rs | 15 | ||||
-rw-r--r-- | 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<Response> { + let html_type = "text/html".parse::<iron::mime::Mime>().unwrap(); + Ok(Response::with((html_type, status::Ok, include_str!("../../swagger-ui/index.html")))) + } + fn yaml_handler(_: &mut Request) -> IronResult<Response> { + 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 @@ -<!-- HTML for static distribution bundle build --> <!DOCTYPE html> <html lang="en"> + <!-- HTML for static distribution bundle build --> <head> <meta charset="UTF-8"> <title>Swagger UI</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet"> - <link rel="stylesheet" type="text/css" href="./swagger-ui.css" > + <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.15.0/swagger-ui.css" > + <!-- <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> + --> <style> html { @@ -34,14 +36,14 @@ <body> <div id="swagger-ui"></div> - <script src="./swagger-ui-bundle.js"> </script> - <script src="./swagger-ui-standalone-preset.js"> </script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.15.0/swagger-ui-bundle.js"> </script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.15.0/swagger-ui-standalone-preset.js"> </script> <script> window.onload = function() { // Build a system const ui = SwaggerUIBundle({ - url: "http://petstore.swagger.io/v2/swagger.json", + url: "/v0/openapi2.yml", dom_id: '#swagger-ui', deepLinking: true, presets: [ |