Skip to content

Instantly share code, notes, and snippets.

@cderv
Last active October 22, 2020 17:02
Show Gist options
  • Save cderv/b4f87cabf9b32141bc4d39a89761ad1b to your computer and use it in GitHub Desktop.
Save cderv/b4f87cabf9b32141bc4d39a89761ad1b to your computer and use it in GitHub Desktop.
Launch swagger json in RStudio Viewer
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