Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rapidoc #147

Open
wants to merge 3 commits into
base: PROD
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Imports:
wbpip,
readr,
glue,
logger
logger,
rapidoc
Remotes:
PIP-Technical-Team/wbpip@master
Depends:
Expand Down
2 changes: 0 additions & 2 deletions R/start_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 0 additions & 7 deletions inst/plumber/v1/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
# }
85 changes: 61 additions & 24 deletions inst/plumber/v1/openapi.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.


23 changes: 21 additions & 2 deletions inst/plumber/v1/plumber.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)