标签: openapi

Swagger 2.0支持矩阵参数吗?

Swagger 2.0是否支持JAX-RS规范的矩阵参数?

JAX-RS 规范有矩阵参数支持。

我的应用程序中存在一些矩阵参数,例如/map/color;lat=50;long=20;scale=32000. 我想为矩阵参数导出 Swagger。我使用http://editor.swagger.io;但我无法在编辑器中得到任何帮助。谁能帮我?

Swagger 2.0支持矩阵参数吗?

与矩阵参数相关的其他链接:

swagger swagger-2.0 swagger-editor openapi

6
推荐指数
1
解决办法
2673
查看次数

编写使用多种内容类型的 swagger 文档,例如 application/json AND application/x-www-form-urlencoded(无重复)

我正在寻找一种优雅的方式来定义可以使用 JSON 数据和表单数据的 api。以下代码段有效,但它并不优雅,并且需要在后端使用各种丑陋的代码。有没有更好的方法来定义这个?

现在什么工作:

paths:
  /pets:
    post:
      consumes:
      - application/x-www-form-urlencoded
      - application/json
      parameters:
      - name: nameFormData
        in: formData
        description: Updated name of the pet
        required: false
        type: string
      - name: nameJSON
        in: body
        description: Updated name of the pet
        required: false
        type: string
Run Code Online (Sandbox Code Playgroud)

我希望它如何工作的基本想法:

paths:
  /pets:
    post:
      consumes:
      - application/x-www-form-urlencoded
      - application/json
      parameters:
      - name: name
        in: 
        - formData
        - body
        description: Updated name of the pet
        required: true
        type: string
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为该in值必须是字符串,而不是数组。

有什么好主意吗?

swagger swagger-2.0 swagger-editor openapi

6
推荐指数
1
解决办法
3260
查看次数

从 Scala 源代码 (http4s) 生成 Swagger/OpenAPI 规范

所以我不是 swagger 专家,但所有使用 swagger 的系统都要求您拥有 JSON 或 YAML 中的 swagger 规范来定义 API 的所有端点(等)。

我的问题是:有没有办法根据实际的源代码生成这些规范文件?我在问,因为当您开始添加属性或返回略有不同的结果时,似乎很难保持端点代码和文档同步。

所以当我有这个代码时(使用 http4s 和 RhoService):

object HelloWorld {
  val service = new RhoService {
    GET / "hello" / 'name |>> { name: String =>
      Ok(Json.obj("message" -> Json.fromString(s"Hello, ${name}")))
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如果它可以产生(以某种方式:)

/hello/{name}:
    get:
      tags:
      - "HelloWorld"
      summary: ""
      description: ""
      operationId: "getHellobyName"
      produces:         
      - "application/json"
      parameters:
      - name: "name"
        in: "path"
        description: ""
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: "#/definitions/Hello"           
      security: …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-2.0 openapi http4s

6
推荐指数
2
解决办法
2536
查看次数

Swagger/OpenAPI 3.0 问题及响应示例

这是我在 Swagger 编辑器在线查看的 OpenAPI 3.0 定义的简化版本。我试图获得错误代码 401 和 403 的两个响应,它们共享相同的架构,显示不同的示例 - 这似乎不起作用,我仍然看到引用的类型作为示例。

您能帮我找出这些定义有什么问题吗?

openapi: 3.0.0
info:
  version: '1.0'
  title: A service
paths:
  /doSomething:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: string
              example: A string
      responses:
        401:
          $ref: '#/components/responses/Unauthorized'
        403:
          $ref: '#/components/responses/Denied'
components:
  responses:
    Unauthorized:
      description: The endpoint cannot be reached because the request is not authorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: unauthorized
    Denied:
      description: The request's authorizations don't match the required ones needed to access the resource
      content:
        application/json: …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui swagger-editor openapi

6
推荐指数
1
解决办法
6085
查看次数

如何在 OpenAPI (Swagger) 中定义双精度数据类型?

对于整数,我使用

userId:
  type: integer
  format: int32
Run Code Online (Sandbox Code Playgroud)

但是如果我想分配 double 类型怎么办?

我尝试查看 Swagger 文档但找不到答案。

swagger openapi

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

如何在整个 Swagger YAML 文档中重复使用我的 x-amazon-apigateway-integration 定义?

我目前正在使用 Swagger 来定义具有许多端点的 API,并且这些端点中的每一个都对“x-amazon-apigateway-integration”键具有相同的定义。我想在文档的某处定义它,并在整个过程中重复使用该定义。

要么我不明白应该如何定义定义,我没有将它放在正确的位置或两者的混合。我尝试在“定义”中定义这个定义,并作为它自己的密钥下的一些别名。定义(删除了关键信息)是:

x-amazon-apigateway-integration:
  responses:
    default:
      statusCode: '200'
  passthroughBehavior: when_no_match
  httpMethod: POST
  uri: >-
    arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
  credentials: '<role arn>'
  type: aws     
  requestTemplates: "application/json": "<object definition>"  
Run Code Online (Sandbox Code Playgroud)

我尝试将其定义为它自己的密钥下的别名(不是定义,而是相同的基本范围):

amazon:
  Amazon: &Amazon
    - responses:
        default:
          statusCode: '200'
    - passthroughBehavior: when_no_match
    - httpMethod: POST
    - uri: >-
    arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/<lambda arn>/invocations
    - credentials: '<role arn>'
    - type: aws     
    - requestTemplates:
      "application/json": "<object definition>"
Run Code Online (Sandbox Code Playgroud)

要使用,我有以下内容:

x-amazon-apigateway-integration:
  *Amazon
Run Code Online (Sandbox Code Playgroud)

API Gateway 导入时收到的错误是“无法解析 API 定义,因为路径 / 中的集成格式错误”

我还尝试在“定义”下定义它,并使用“参考”来访问它:

definitions:
  Amazon:
    type: object
    x-amazon-apigateway-integration:
      responses:
        default:
          statusCode: '200'
      passthroughBehavior: …
Run Code Online (Sandbox Code Playgroud)

yaml amazon-web-services swagger openapi

6
推荐指数
2
解决办法
2050
查看次数

OpenAPI CodeGen for Spring-Webflux / Mono 或 Flux 对象作为返回

最新版本的 OpenApi Codegen(及其 Maven 插件)能够/应该能够使用 Webflux/Reative 返回对象(例如 Mono 或 Flux 对象)为 spring maven 自动生成接口。然而,我认为无法让它发挥作用。这些是我的 pom.xml 的摘录:

    <plugin>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>${swagger.codegen.version}</version>
        <executions>
        <!-- AUTHENTICATION-API -->
            <execution>
              <id>authentication-api</id>
              <goals>
                <goal>generate</goal>
              </goals>
              <configuration>
                <inputSpec>src/main/resources/swagger/authentication.yaml</inputSpec>
                <language>spring</language>
                <configOptions>
                  <sourceFolder>src/main/java</sourceFolder>
                    <library>spring-boot</library>
                    <!-- <async>true</async> -->
                    <reactive>true</reactive>
                    <dateLibrary>java8</dateLibrary>
                    <useTags>true</useTags>
                    <apiPackage>${project.groupId}.api</apiPackage>
                    <modelPackage>${project.groupId}.model</modelPackage>
                    <interfaceOnly>true</interfaceOnly>
                </configOptions>
              </configuration>
            </execution>
         </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

这些是authentication.yaml和生成的接口的摘录

身份验证.yaml

paths:
  /dotcmsAuthentication:
    get:
      tags:
        - authentication
        - dotCMS
      description: Returns dotCMS json with JWT Token.
      operationId: getDotcmsAuthentication
      produces:
        - application/json
      consumes:
        - application/json
      parameters:
        - name: DotcmsAuthentication
      in: header …
Run Code Online (Sandbox Code Playgroud)

java mono spring openapi reactive

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

Java Enum 上的 OpenAPI 和 @Schema 注释

我正在从带注释的 Java 代码生成 OpenAPI 3.0 文档。但问题是,当我添加 @Schema 注释来枚举所有值时,所有值都消失了。我正在使用带有 microprofile-openapi 分数的 Thorntail 2.3.0.Final。

我知道我可以只更改 .yaml 文件,但我需要直接从 Java 代码生成我的 yaml。

这是我在 github 上的最小示例:https : //github.com/pkristja/openApiEnumSchema

枚举的源代码:

package com.example.openapiexample.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

@Schema(description = "<div class=\\\"renderedMarkdown\\\"><p>Rank of developer.</p>\\n\" +\n" +
        "        \"<p>Valid values are:</p>\\n\" +\n" +
        "        \"<ul>\\n\" +\n" +
        "        \"<li>'JUNIOR_DEVELOPER_1': Text for junior 1.\\n\" +\n" +
        "        \"<li>'JUNIOR_DEVELOPER_2': Text for junior 2.\\n\" +\n" +
        "        \"<li>'JUNIOR_DEVELOPER_3': Text for junior 3.\\n\" +\n" +
        "        \"<li>'SENIOR_DEVELOPER_1': Text for senior …
Run Code Online (Sandbox Code Playgroud)

java swagger openapi microprofile thorntail

6
推荐指数
1
解决办法
6991
查看次数

OpenAPI 中的服务版本控制

我们即将为我的客户端实现一个服务 API,它由许多服务组成,比如说 ServiceA、ServiceB 和 ServiceC。每个服务都可以随着时间的推移(独立地)引入新版本,而旧版本仍然存在。所以我们可能有:

  • 服务A v1
  • 服务A v2
  • 服务B v1
  • 服务C v1
  • 服务C v2
  • 服务C v3

我们需要使用 OpenAPI 记录此 API。我对 OpenAPI 不太熟悉,但据我所知,您通常对整个 API 进行版本控制,而不是单独的服务。

通常如何使用 OpenAPI 记录此类版本控制?我个人认为有两种选择,但我很可能遗漏了一些东西:

  1. 在文档中将相同服务的每个版本添加为单独的服务(但随着时间的推移,这会导致 API 臃肿,其中包含大量服务)
  2. 每次单个服务更改版本时,增加所有服务版本和整个 API 的版本,因此每个服务总是有版本 1、2 和 3,即使其中一些是相同的(但这会引入很多不必要的服务版本)。

任何输入将不胜感激。

openapi

6
推荐指数
1
解决办法
308
查看次数

在 Swagger openAPI 注释中发出“授权:持有者 &lt;令牌&gt;”

我使用这些包(通过作曲家安装)

"swagger-api/swagger-ui": "^3.0",
"zircote/swagger-php": "~2.0|3.*"

在我的 def 控制器中,我有这些注释

/**
 * @OA\Info(title="My API", version="0.1")
 * @OA\Schemes(format="http")
 * @OA\SecurityScheme(
 *      securityScheme="bearerAuth",
 *      in="header",
 *      name="Authorization",
 *      type="http",
 *      scheme="Bearer",
 *      bearerFormat="JWT",
 * ),
 * @OA\Tag(
 *     name="Auth",
 *     description="Auth endpoints",
 * )
 * @OA\Tag(
 *     name="Users",
 *     description="Users endpoints",
 * )
 */
class Controller extends BaseController
Run Code Online (Sandbox Code Playgroud)

然后我有方法

/**
 * 
 * @OA\Get(
 *      path="/users",
 *      operationId="getListOfUsers",
 *      tags={"Users"},
 *      description="Get list of users",
 *      security={{"bearerAuth":{}}}, 
 *      @OA\Parameter(
 *         name="Authorization",
 *         in="header",
 *         required=true, …
Run Code Online (Sandbox Code Playgroud)

php swagger swagger-php openapi

6
推荐指数
1
解决办法
8634
查看次数