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

ref component Parameters in YAML causes error #16

Open
slodge opened this issue Dec 3, 2020 · 2 comments
Open

ref component Parameters in YAML causes error #16

slodge opened this issue Dec 3, 2020 · 2 comments

Comments

@slodge
Copy link

slodge commented Dec 3, 2020

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
@slodge
Copy link
Author

slodge commented Dec 4, 2020

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"

@slodge
Copy link
Author

slodge commented Jan 27, 2022

I think this is resolved in #19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant