rapiclient
rapiclient copied to clipboard
ref component Parameters in YAML causes error
I'm looking at some YAML at the moment which has a parameter defined as a $ref
.
This causes a problem at call time of:
Error in build_op_url(api, api$schemes[1], api$host, api$basePath, op_def, :
Not all parameters have a location
Is this something that's already supported somehow?
If not, then I might experiment to see if I can assist...
Example YAML snippet:
paths:
/things:
get:
tags:
- Things
summary: List all things
operationId: ListThings
parameters:
- name: ids
in: query
description: Restrict to the IDs in the comma-separated list.
schema:
type: array
items:
type: string
format: case-insensitive
- $ref: '#/components/parameters/Expand_Thing'
and later:
parameters:
Expand_Thing:
name: expand
in: query
description: The fields of the thing which should be hydrated from IDs into the data type they represent. _(**Warning:** Assigning this parameter is not supported in the latest version of the NSwag client at present.)_
schema:
type: array
items:
title: ThingField
enum:
- Option1
- Option2
type: string
It's "a bit hacky" but this code patches up the GET calls at least:
library(rapiclient)
api <- rapiclient::get_api("https://.../swagger.yaml")
api$paths %>%
purrr::iwalk(function(path, path_key) {
if (is.null(path$get)) return()
if (is.null(path$get$parameters)) return()
path$get$parameters %>%
purrr::iwalk(function(parameter, parameter_key) {
ref <- parameter[["$ref"]]
if (is.null(ref)) return()
parts <- ref %>% str_split("/") %>% pluck(1)
if (parts[1] != "#") {
message("Don't know how to handle references which don't start with '#'")
return()
}
parts <- parts %>% tail(-1)
extractor <- as_mapper(parts)
replacement <- extractor(api)
message("replacing p", parameter_key, " on get for ", path_key)
api$paths[[path_key]]$get$parameters[[parameter_key]] <<- replacement
})
})
# use api "normally"
I think this is resolved in #19