diff --git a/DESCRIPTION b/DESCRIPTION index 0022500d..51fde637 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,8 @@ Imports: wbpip, readr, glue, - logger + logger, + rapidoc Remotes: PIP-Technical-Team/wbpip@master Depends: diff --git a/R/start_api.R b/R/start_api.R index 476e4c18..d57ce7b4 100644 --- a/R/start_api.R +++ b/R/start_api.R @@ -18,6 +18,4 @@ start_api <- function(api_version = "v1", api <- source(api_path) plumber::pr_run(api$value, host = host, port = port) - # plumber::plumb_api('pipapi', name = api_version) %>% - # plumber::pr_run(host = host, port = port) } diff --git a/inst/plumber/v1/endpoints.R b/inst/plumber/v1/endpoints.R index 9e45d7c8..41110128 100644 --- a/inst/plumber/v1/endpoints.R +++ b/inst/plumber/v1/endpoints.R @@ -345,10 +345,3 @@ function(req) { params$version <- NULL do.call(pipapi::ui_svy_meta, params) } - -# # Update UI -# #* @plumber -# function(pr) { -# pr %>% -# plumber::pr_set_api_spec(yaml::read_yaml("openapi.yaml")) -# } diff --git a/inst/plumber/v1/openapi.yaml b/inst/plumber/v1/openapi.yaml index a1b4c1bb..f149035f 100644 --- a/inst/plumber/v1/openapi.yaml +++ b/inst/plumber/v1/openapi.yaml @@ -1,6 +1,6 @@ openapi: 3.0.0 info: - description: This API computes all poverty and statistics available at pip.worldbank.org + description: This API computes all poverty and inequality statistics available at pip.worldbank.org title: Poverty and Inequality Platform API version: 0.0.1 paths: @@ -11,24 +11,65 @@ paths: default: description: Default response. parameters: [] - /api/v1/info: + /api/v1/versions: get: - summary: ' Returns information about the API and the available data versions' + summary: ' Return available data versions' responses: default: description: Default response. parameters: [] - /api/v1/get-cpi: + /api/v1/pip-info: get: - summary: ' Download CPI table as .csv' + summary: ' Return information about the API' responses: default: description: Default response. parameters: [] + /api/v1/valid-params: + get: + summary: ' Return valid query parameters' + responses: + default: + description: Default response. + parameters: + - in: query + name: version + schema: + type: string + description: Data version. Defaults to most recent version. See api/v1/versions. + - in: query + name: format + schema: + type: string + enum: [json, csv, rds] + description: Response format. Defaults to json. + /api/v1/aux: + get: + summary: ' Return auxiliary data tables' + responses: + default: + description: Default response. + parameters: + - in: query + name: table + schema: + type: string + description: Auxiliary data table to be returned. + - in: query + name: version + schema: + type: string + description: Data version. Defaults to most recent version. See api/v1/versions. + - in: query + name: format + schema: + type: string + enum: [json, csv, rds] + description: Response format. Defaults to json. /api/v1/pip: get: summary: ' Return main poverty and inequality statistics' - description: Main function to compute poverty and inequality statistics + description: Main function to compute poverty and inequality statistics. parameters: - in: query name: country @@ -76,13 +117,13 @@ paths: schema: type: boolean example: FALSE - description: Whether to aggregate results (Population weighted average) + description: Whether to aggregate results (Population weighted average). - in: query name: group_by schema: type: string enum: [wb, inc] - description: Aggregate results by pre-defined sub-groups + description: Aggregate results by pre-defined sub-groups. - in: query name: welfare_type schema: @@ -94,22 +135,18 @@ paths: schema: type: string enum: [all, national, rural, urban] - description: Survey coverage + description: Reporting coverage. + - in: query + name: version + schema: + type: string + description: Data version. Defaults to most recent version. See api/v1/versions. + - in: query + name: format + schema: + type: string + enum: [json, csv, rds] + description: Response format. Defaults to json. responses: '200': description: successful message - /api/v1/hp-stacked: - get: - summary: ' Return data for PIP homepage main chart' - description: Return data for PIP homepage main chart. Stacked line chart. - parameters: - - in: query - name: povline - schema: - type: number - minimum: 0 - maximum: 100 - example: 1.90 - description: Poverty line to be used to compute poverty mesures. - - diff --git a/inst/plumber/v1/plumber.R b/inst/plumber/v1/plumber.R index 388bad20..d7cc957a 100644 --- a/inst/plumber/v1/plumber.R +++ b/inst/plumber/v1/plumber.R @@ -1,9 +1,11 @@ library(plumber) +library(rapidoc) library(logger) library(glue) endpoints_path <- system.file("plumber/v1/endpoints.R", package = "pipapi") -convert_empty <- pipapi:::convert_empty +api_spec_path <- system.file("plumber/v1/openapi.yaml", package = "pipapi") +# convert_empty <- pipapi:::convert_empty plumber::pr(endpoints_path) %>% # pre-route log @@ -29,7 +31,24 @@ plumber::pr(endpoints_path) %>% plumber::pr_hook("exit", function() { # log_info('Bye bye: {proc.time()[["elapsed"]]}') }) %>% + # Set API spec plumber::pr_set_api_spec(api = function(spec) { spec$info$version <- utils::packageVersion("pipapi") %>% as.character() spec - }) + }) %>% + plumber::pr_set_api_spec( + yaml::read_yaml(api_spec_path)) %>% + # Style doc page + plumber::pr_set_docs( + "rapidoc", + show_info = TRUE, + show_header = FALSE, + bg_color = "#FFFFF", + text_color = "#343A40", + primary_color = "#007BFF", + regular_font = "sans-serif", + mono_font = "monospace", + font_size = "default", + # render_style = "view", + # sort_endpoints_by = "none" + )