Closed tezansahu closed 4 years ago
tags
should be an array. read_yaml
return a character
vector of length 1 for tags
. It should be a list
.
You can make it work this way, but you will have to find something else if you want to generalize this solution.
root$run(port=8000, swagger = function(pr, spec, ...) {
spec <- yaml::read_yaml("../issue.yaml")
spec$paths$`/echo/echo`$get$tags <- list(spec$paths$`/echo/echo`$get$tags)
spec
})
What happens is read_yaml
reads your tags
as a single character
vector instead of a list
. It then gets transformed into json with tags
being "tags":"echo"
. Swagger expects a list
so it interprets it as a list of individual characters. Tags should be enclosed in square brackets []
in a valid OpenAPI specification.
Another easy alternative would be to add a second useless tag
# api-spec.yaml
openapi: 3.0.0
servers:
- description: Localhost
url: http://127.0.0.1:8000
info:
description: This is a simple Plumber API with the spec defined in an external file
version: "1.0.0"
title: Simple Plumber
paths:
/echo/echo:
get:
summary: Echos back a message
tags:
- echo
- +
description: |
Pass a message and have it echoed in return in JSON
parameters:
- in: query
name: msg
description: Message to echo in return
required: true
schema:
type: string
responses:
'200':
description: successful message
This is not a plumber issue, sorry
Thanks a lot @meztez ! It worked like a charm.
Instead of a second useless tag like +
(which leads to the appearance of an extra unnecessary section called "+" in the swagger documentation), I actually used an empty tag...that did not result in any extra section other than those that I had actually tagged.
Looked something like this:
paths:
/echo/echo:
get:
summary: Echos back a message
tags:
- echo
-
description: |
Pass a message and have it echoed in return in JSON
parameters:
- in: query
name: msg
description: Message to echo in return
required: true
schema:
type: string
responses:
'200':
description: successful message
@tezansahu Can you close the issue?
System details
Output of
sessioninfo::session_info()
:Example application or steps to reproduce the problem
These are files (all to be placed in the same folder) necessary for reproducing the issue:
api-spec.yaml
:echo.R
:start_server.R
:Now, run the start_server.R & inspect the Swagger documentation produced at
http://127.0.0.1:8000/__swagger__/
Describe the problem in detail
The segregation into sections using
tags
behaves weirdly as shown: Instead of the whole worldecho
, each letter of the word becomes a new section. I tried to write the tag as"echo"
as well as'echo'
, but still the problem persists.However, while testing the same YAML file on online Swagger editor, it behaves normally as shown:
I am unable to understand what is going wrong with the same file when being used in
plumber
.