Created
June 7, 2023 15:38
-
-
Save randrescastaneda/ee2ca99e5b311f13c947088bfe5e1edc to your computer and use it in GitHub Desktop.
Parse PIP API endpoints documentation to text file
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
library(data.table) | |
url <- "https://raw.githubusercontent.com/PIP-Technical-Team/pipapi/master/inst/plumber/v1/endpoints.R" | |
lns <- readLines(con = url) |> | |
{\(.) .[grep("\\@(get|param)", .)]}() | |
dt <- data.table(lines = lns) | |
dt[grep("\\@get", lines), | |
endpoint := gsub("(.+)/([^/]+)$", "\\2", lines) | |
][, | |
# fill in NAs | |
endpoint := vctrs::vec_fill_missing(endpoint) | |
][ | |
# get parameters | |
grep("\\@param", lines), | |
param := gsub("(.+param )(.+):(.*)", "\\2", lines) | |
][ | |
# get type | |
grep("\\@param", lines), | |
type := gsub("(.+):\\[(.*)\\](.+)", "\\2", lines)] | |
# get onl y params rows | |
dl <- dt[!grepl("\\@get", lines) | |
][, | |
lines := NULL] |> | |
split(by = "endpoint", keep.by = FALSE) | |
in_yml <- ymlthis::as_yml(dl) | |
in_json <- jsonlite::toJSON(dl, pretty = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment