为什么 Swagger UI 将字符串示例生成为 "StringStri" 而不是 "string"?
Why does Swagger UI generate string examples as "StringStri" instead of "string"?
我们在 Swagger 的 OpenAPI 预览中得到“stringstri”而不是“string”类型 UI。
问题:
- 当
minLength
为 7 - 我们在预览中得到“字符串”
- 当
minLength
为 8 - 我们在预览中得到“stringst”
- 当
minLength
为 9 - 我们在预览中得到“stringstr”
类似的继续。
预期 - 只有“字符串”。
重现问题的示例架构:
components:
schemas:
Manufacturer:
required:
- name
properties:
name:
type: string
minLength: 10
maxLength: 2048
Swagger UI 显示此架构的以下示例:
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "Widget Adapter",
"releaseDate": "2021-05-17T06:52:27.542Z",
"manufacturer": {
"name": "stringstri",
"homePage": "string",
"phone": "string"
}
}
name
属性 有 minLength: 10
这就是示例值生成为 10 个字符长的原因。值“string”只有 6 个字符长,因此它不是 属性 和 minLength
>= 7 的有效示例,这就是 Swagger UI 在这种情况下填充值的原因。
如果需要,您可以提供自己的 example
值:
properties:
name:
type: string
minLength: 10
maxLength: 2048
example: Acme Corporation # <-----
我们在 Swagger 的 OpenAPI 预览中得到“stringstri”而不是“string”类型 UI。
问题:
- 当
minLength
为 7 - 我们在预览中得到“字符串” - 当
minLength
为 8 - 我们在预览中得到“stringst” - 当
minLength
为 9 - 我们在预览中得到“stringstr”
类似的继续。
预期 - 只有“字符串”。
重现问题的示例架构:
components:
schemas:
Manufacturer:
required:
- name
properties:
name:
type: string
minLength: 10
maxLength: 2048
Swagger UI 显示此架构的以下示例:
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "Widget Adapter",
"releaseDate": "2021-05-17T06:52:27.542Z",
"manufacturer": {
"name": "stringstri",
"homePage": "string",
"phone": "string"
}
}
name
属性 有 minLength: 10
这就是示例值生成为 10 个字符长的原因。值“string”只有 6 个字符长,因此它不是 属性 和 minLength
>= 7 的有效示例,这就是 Swagger UI 在这种情况下填充值的原因。
如果需要,您可以提供自己的 example
值:
properties:
name:
type: string
minLength: 10
maxLength: 2048
example: Acme Corporation # <-----