管道工:在 UI 中获取请求正文/架构

发布于 2025-01-12 23:04:36 字数 1739 浏览 1 评论 0原文

我正在尝试制作一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光清浅 2025-01-19 23:04:36

我可能已经找到了至少一个解决这个

水管工问题

v <- list(number = 40)

#* @apiTitle test API
#* @apiDescription an api

#* test
#* @put /test_json
#* @param input:object
function(input = v){
  new_data <- unlist(v)
  return(new_data)
}

的方法。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

v <- list(number = 40)

#* @apiTitle test API
#* @apiDescription an api

#* test
#* @put /test_json
#* @param input:object
function(input = v){
  new_data <- unlist(v)
  return(new_data)
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文