-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add openapi explorer api viewer * Specify font family for openapi explorer * Fix mislabeled comment
- Loading branch information
1 parent
a37b07a
commit ec3deb8
Showing
6 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use poem::{endpoint::make_sync, web::Html, Endpoint}; | ||
|
||
const REDOC_JS: &str = include_str!("openapi-explorer.min.js"); | ||
|
||
const REDOC_TEMPLATE: &str = r#" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>OpenAPI Explorer</title> | ||
<!-- needed for adaptive design --> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet"> | ||
<style type="text/css"> | ||
:root { | ||
--font-regular: Montserrat; | ||
} | ||
</style> | ||
<script charset="UTF-8">{:script}</script> | ||
</head> | ||
<body> | ||
<openapi-explorer></openapi-explorer> | ||
<script> | ||
let spec = {:spec}; | ||
document.getElementsByTagName('openapi-explorer')[0].loadSpec(spec).catch(console.error); | ||
</script> | ||
</body> | ||
</html> | ||
"#; | ||
|
||
pub(crate) fn create_html(document: &str) -> String { | ||
REDOC_TEMPLATE | ||
.replace("{:script}", REDOC_JS) | ||
.replace("{:spec}", document) | ||
} | ||
|
||
pub(crate) fn create_endpoint(document: &str) -> impl Endpoint { | ||
let ui_html = create_html(document); | ||
poem::Route::new().at("/", make_sync(move |_| Html(ui_html.clone()))) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.