管道工:在 UI 中获取请求正文/架构
我正在尝试制作一个 R 管道工 api,它在 docs UI 界面中具有示例请求正文/架构,类似于这些视频中显示的内容 (https://www.rstudio.com/resources/rstudioconf-2019/democratizing-r-with-plumber-apis/ 或 https://www.youtube.com/watch?v=J0Th2QRZ7Rk )
我尝试使用 yaml 设置正文,类似于下面的第二个视频。但是,当我打开文档时,我没有看到任何正文示例/架构按下“尝试”的响应图像我希望看到一个带有“编辑值”和“模式”选项的请求
。
#* @apiTitle test API
#* @apiDescription an api
#* test
#* @put /test_json
function(res, req){
new_data <- req$body
return(new_data)
}
function(pr){
pr %>% pr_set_api_spec(yaml::read_yaml(paste0(getwd(), "/openapi.yaml")))
}
主体
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/test_json:
post:
summary: 'A test'
responses:
default:
description: Default response
parameters: []
requestBody:
description: some data
required: true
content:
application/json:
schema:
type: object
properties:
number:
type: number
title: "A number"
example: 40
I'm trying to make a R plumber api that has a example request body/schema in the docs UI interface, similar to what is shown in these videos (https://www.rstudio.com/resources/rstudioconf-2019/democratizing-r-with-plumber-apis/ , or https://www.youtube.com/watch?v=J0Th2QRZ7Rk )
My attempt to set the body using yaml, similar to the second video is below. However, I don't see any body example/schema when I open the docs image of response to pressing "try it out" + "execute. I was hoping to see a Request body with "edit value" and "schema" options.
plumber.R
#* @apiTitle test API
#* @apiDescription an api
#* test
#* @put /test_json
function(res, req){
new_data <- req$body
return(new_data)
}
function(pr){
pr %>% pr_set_api_spec(yaml::read_yaml(paste0(getwd(), "/openapi.yaml")))
}
openapi.yaml
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/test_json:
post:
summary: 'A test'
responses:
default:
description: Default response
parameters: []
requestBody:
description: some data
required: true
content:
application/json:
schema:
type: object
properties:
number:
type: number
title: "A number"
example: 40
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能已经找到了至少一个解决这个
水管工问题
的方法。R给了我想要的身体
[文档中的正文][1]
我找到了一些其他示例,说明如何在此处完成此操作 https: //github.com/rstudio/plumber/issues/768
[1]: https://i.sstatic.net/ZOhGw.png
I may have found at least one solution to this
plumber.R
gives me the desired body
[body in docs][1]
I found some other examples of how this could be done here https://github.com/rstudio/plumber/issues/768
[1]: https://i.sstatic.net/ZOhGw.png