Last active
October 22, 2020 17:02
-
-
Save cderv/b4f87cabf9b32141bc4d39a89761ad1b to your computer and use it in GitHub Desktop.
Launch swagger json in RStudio Viewer
This file contains hidden or 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
swagger_viewer <- function(json_doc) { | |
folder_path <- fs::path_temp("swagger") | |
if (!fs::dir_exists(folder_path)) { | |
fs::dir_copy(swagger::swagger_path(), folder_path) | |
} | |
fs::file_copy(json_doc, folder_path) | |
index <- xfun::read_utf8(fs::path_temp("swagger", "index.html")) | |
index_new <- gsub("http://petstore.swagger.io/v2/swagger.json", json_doc, index) | |
xfun::write_utf8(index_new, fs::path_temp("swagger", "index.html")) | |
rstudioapi::viewer(fs::path_temp("swagger", "index.html")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment