标签: openapi

从 Swagger/OpenAPI 生成 Spring MVC 控制器

有没有办法从 Swagger/OpenAPI 规范生成控制器 Spring MVC 代码?

我知道 Swagger 可以从现有的 Spring 代码生成,但这是否可能反过来?

java http spring-mvc swagger openapi

3
推荐指数
1
解决办法
8092
查看次数

如何在 Swagger 编辑器中将 JSON 对象作为多部分请求的一部分发送?

我正在使用 Swagger 编辑器编写 API 文档,但在包含 JSON 对象的多部分 POST 请求中遇到问题。这是我的 Swagger YAML 文件:

swagger: '2.0'
info:
  version: 1.0.0
  title: Documentation API
paths:
  /agent:
    post:
      consumes:
      - multipart/form-data
      produces:
      - text/html
      parameters:
      - in: query
        name: method
        description: name of method to access
        required: true
        type: string
      - in: body
        name: param
        description: parameter to send
        required: true
        schema:
            $ref: "#/definitions/Param"
      responses:
        201:
          description: item created
        400:
          description: invalid input, object invalid
        409:
          description: an existing item already exists
definitions:
  Param:           # …
Run Code Online (Sandbox Code Playgroud)

swagger-2.0 swagger-editor openapi

3
推荐指数
1
解决办法
1万
查看次数

我该如何在swagger规格中表示十进制浮点数?

我想在我的api文档中表示小数点后2位和小数点后1位。我正在使用swagger 2.0,规格中是否有内置定义的类型或任何其他“圆形”参数,或者我唯一的选择是使用“ x-”扩展名?

swagger swagger-2.0 openapi

3
推荐指数
1
解决办法
4980
查看次数

如何使用 OpenAPI 记录由资源列表组成的响应

我正在尝试创建 OpenAPI yml 文档文件(通过 swagger)。我的 API 调用之一返回资源列表。每个资源都有属性、一个自链接和一个到附加链接的链接,该链接将检索与资源相关的附加“资料”。

请看下面的例子:

[
  {
    "name": "object-01",
    "links": [
      {
        "rel": "self",
        "href": "http://localhost:8800/foo/object-01"
      },
      {
        "rel": "Supported stuff",
        "href": "http://localhost:8800/foo/object-01/stuff"
      }
    ]
  }, {
    "name": "object-02",
    "links": [
      {
        "rel": "self",
        "href": "http://localhost:8800/foo/object-02"
      },
      {
        "rel": "Supported stuff",
        "href": "http://localhost:8800/foo/object-02/stuff"
      }
    ]
  }, {
    "name": "object-03",
    "links": [
      {
        "rel": "self",
        "href": "http://localhost:8800/foo/object-03"
      },
      {
        "rel": "Supported stuff",
        "href": "http://localhost:8800/foo/object-03/stuff"
      }
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

我不确定记录这一点的正确方法是什么,这就是我现在所拥有的。

  paths:
    /foo/objects:
      get:
        operationId: getObject
        responses:
          '200':
            description: Respresentation …
Run Code Online (Sandbox Code Playgroud)

rest hateoas swagger-editor openapi

3
推荐指数
1
解决办法
3048
查看次数

如何描述使用的OpenAPI(扬鞭)一个多反应?

我有一个创建包含以下内容的多部分文件的服务:

  • 代表图像缓冲区的数据字节数组
  • 一个JSON表示关于图像(坐标,格式等)的信息

是否有可能使用YAML在提供的OpenAPI(扬鞭)定义这个自定义响应模型,?

multipart swagger openapi

3
推荐指数
1
解决办法
1882
查看次数

使用未命名对象数组创建招摇/开放 API 响应

我从 http 请求中得到以下形式的响应:它是一个未命名数组和对象的数组。对于这种情况,我无法找出正确的 Swagger(Open API)规范。

[
  [
    {
      "prop1": "hello",
      "prop2": "hello again"
    },
    {
      "prop1": "bye",
      "prop2": "bye again"
    }
  ],
  {
    "key": 123
  }
]
Run Code Online (Sandbox Code Playgroud)

swagger openapi

3
推荐指数
2
解决办法
9625
查看次数

使用OpenAPI v3规范定义一个或多个字符串数组的正确方法

我希望发布一个包含可变数量字符串的数组,例如

[“ string1”,“ string2”,...“ stringN”]

我现在的OpenAPI文档是这样定义的:

schema:
  type: array
    items:
      description: networkIds
      type: string
Run Code Online (Sandbox Code Playgroud)

这是按照OpenAPi v3规范进行编码的正确方法,还是有一种更精确的方法来指示数组中的一个或多个字符串?

arrays swagger openapi

3
推荐指数
1
解决办法
1631
查看次数

使用Swagger 3.0发送cookie会话ID

据说"要定义cookie身份验证,请改用API密钥".在官方文档中

https://swagger.io/docs/specification/describing-parameters/#cookie-parameters

事实是我们尝试过

components:
  securitySchemes:
    cookieAuth:         
      type: apiKey
      in: cookie
      name: sessionId
...
    security:
      - cookieAuth: []
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,在Swagger UI中,我们可以单击挂锁来设置sessionId的值.但是当我们执行该方法时,cookie的值为NULL,我们看不到在Headers中发送的cookie(Chrome Developer工具)

我也尝试将其放在cookie参数中,如下所示:

parameters:
  - in: cookie
    name: sessionId   
    required: true
    schema:
      type: string 
Run Code Online (Sandbox Code Playgroud)

但是,同样的结果(到达null,调试器工具中没有任何内容).

我们使用Swagger和openApi 3.0,其他参数,requestBody运行良好,但不是这个cookie传输.

对于任何有想法的东西都可以.

authentication cookies swagger openapi

3
推荐指数
1
解决办法
1840
查看次数

如何在OpenAPI 3中定义另一个模式的数组?

我定义了以下架构:

User:
  type: object
  required:
    - id
    - username
  properties:
    id:
      type: integer
      format: int32
      readOnly: true
      xml:
        attribute: true
      description: The user ID
    username:
      type: string
      readOnly: true
      description: The username
    first_name:
      type: string
      description: Users First Name
    last_name:
      type: string
      description: Users Last Name
    avatar:
      $ref: '#/components/schemas/Image'
  example:
    id: 10
    username: jsmith
    first_name: Jessica
    last_name: Smith
    avatar: image goes here
  xml:
    name: user
Run Code Online (Sandbox Code Playgroud)

效果很好。该GET /user/{id}调用会很好地显示示例数据。

我有第二个架构,可以创建上述架构的数组:

ArrayOfUsers:
  type: array
  items:
    type: object
    required:
      - id
      - …
Run Code Online (Sandbox Code Playgroud)

swagger openapi

3
推荐指数
1
解决办法
1618
查看次数

如何修复ErrorException:当@OA \ Property()类型为“数组”时,需要@OA \ Items()?

我试图添加任意类型的嵌套数组。这些是我的注释:

* @OA\Property(
*      @OA\Schema(
*          type="array",
*          @OA\Items(
*              type="array",
*              @OA\Items(type={})
*          )
*      ),
*      description="bla bla bla"
* )
Run Code Online (Sandbox Code Playgroud)

php swagger-php openapi

3
推荐指数
1
解决办法
1150
查看次数