首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Api平台自定义swagger/openapi上下文体

Api平台自定义swagger/openapi上下文体
EN

Stack Overflow用户
提问于 2019-10-23 12:01:33
回答 2查看 4.1K关注 0票数 0

我正在使用带有Symfony 4的Api平台,并且我想创建一个自定义端点。一切正常,但是我不能改变两件事:主体和响应格式(在openapi文档中)。

参数和响应状态代码工作正常。

代码语言:javascript
代码运行次数:0
运行
复制
*          "login"={
 *              "route_name"="api_login",
 *              "method" = "post",
 *              "openapi_context" = {
 *                  "parameters" = {},
 *                  "body" = {
 *                      "description" ="Username and password",
 *                      "schema" = {
 *                          "type" = "object",
 *                          "required" = {"email","password"},
 *                          "properties" = {
 *                                   "email" = {
 *                                      "type" = "string"
 *                                   },
 *                                   "password" = {
 *                                      "type" = "string"
 *                                   }
 *                          }
 *                      }
 *                  },
 *                  "responses" = {
 *                      "200" = {
 *                          "description" = "User logged in",
 *                          "schema" =  {
 *                              "type" = "object",
 *                              "required" = {
 *                                  "token",
 *                                  "refresh_token"
 *                              },
 *                              "properties" = {
 *                                   "token" = {
 *                                      "type" = "string"
 *                                   },
 *                                   "refresh_token" = {
 *                                      "type" = "string"
 *                                   }
 *                              }
 *                          }
 *                      },
 *                      "401" = {
 *                          "description" = "invalid password or email"
 *                      }
 *                  },
 *                  "summary" = "Login user in application",
 *                  "consumes" = {
 *                      "application/json",
 *                      "text/html",
 *                   },
 *                  "produces" = {
 *                      "application/json"
 *                   }
 *              }
 *          }
EN

回答 2

Stack Overflow用户

发布于 2020-04-14 02:51:01

这适用于我,请参阅文档。https://swagger.io/docs/specification/describing-request-body/

代码语言:javascript
代码运行次数:0
运行
复制
 * @ApiResource(
 *     collectionOperations={
 *         "get": {
 *             "method": "GET",
 *             "access_control": "is_granted('ROLE_USER', object)",
 *         },
 *         "post": {
 *             "method": "POST",
 *             "access_control": "is_granted('ROLE_USER', object)",
 *             "openapi_context": {
 *                 "requestBody": {
 *                     "content": {
 *                         "application/ld+json": {
 *                             "schema": {
 *                                 "type": "object",
 *                                 "properties": {
 *                                     "token": {"type": "string", "example": "email@example.com"},
 *                                     "refresh_token": {"type": "string", "example": "123456"},
 *                                 },
 *                             },
 *                         },
 *                     },
 *                 },
 *             },
 *         },
 *     }
 * )
票数 2
EN

Stack Overflow用户

发布于 2019-10-25 03:47:48

看看this response on api-platform的问题(这里的文档是用yaml很好地格式化的,而不是保存在php数组中,这是个不错的主意)和read the docs,它们可能会帮助你以任何你想要的方式装饰文档。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58515294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档