Swagger 2.0 是否支持矩阵参数?

Does Swagger 2.0 support matrix parameters?

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

JAX-RS specification have Matrix-Parameter支持。

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

Swagger 2.0 是否支持矩阵参数?

其他指向矩阵参数的链接:

Swagger 2.0 spec 没有提及任何关于 JAX-RS 矩阵参数的内容。

同时查看 swagger-jaxrs 实现,您可以看到 @MatrixParamthe class 中被忽略,负责扫描 JAX-RS 参数注释。

OpenAPI/Swagger 2.0 不支持矩阵参数,但在 OpenAPI 3.0 中支持。

使用 OpenAPI 3.0,您的示例:

/map/color;lat=50;long=20;scale=32000

可以定义为:

openapi: 3.0.1
...
paths:
  /map/color{params}:
    get:
      parameters:
        - in: path
          name: params
          required: true

          # Named matrix parameters are defined as object properties
          schema:
            type: object
            properties:
              lat:
                type: integer
                example: 50
              long:
                type: integer
                example: 20
              scale:
                type: integer
                example: 32000

          # Serialize this object as ;prop1=value2;prop2=value2 etc
          style: matrix
          explode: true

招摇UI/Editor支持

这在 Swagger UI 3.15.0+ 和 Swagger Editor 3.5.6+ 中受支持。在参数编辑器中,以 JSON 对象格式输入参数名称和值,例如:

{
  "lat": 50,
  "long": 20,
  "scale": 32000
}

"Try it out" 会将这些参数作为矩阵参数发送到 URL:

Swagger-Core支持

对于使用 Java 注释的用户,swagger-core 2.0 支持 @MatrixParam@MatrixParam 对应 OpenAPI 3.0 的路径参数 style: matrix(如上例所示)。