英文:
Is there a way to require two array properties on an object to have the same length?
问题
我正在尝试修改一个Swagger模型。我的目标是将一个对象附加的两个属性从字符串改为字符串数组。到目前为止,我有以下代码:
config:
type: object
minLength: 1
required:
- field1
- field2
properties:
field1:
type: array
minItems: 1
items:
type: string
pattern: '[a-zA-Z]*'
x-nullable: false
field2:
type: array
minItems: 1
items:
type: string
pattern: '[a-zA-Z]*'
x-nullable: false
之前,这两个字段的定义是现在的项定义。这些修改基本上满足了我的需求,但是我想要求field1
和field2
这两个数组具有相同的长度。有没有办法做到这一点?我可以看到如何修改生成的文件来满足这个要求,但是我非常不想每次重新生成文件时都要这样做。
英文:
I'm trying to modify a swagger model. My goal is two change a pair of properties attached to an object that are currently strings to be arrays of strings. Thus far I have
config:
type: object
minLength: 1
required:
- field1
- field2
properties:
field1:
type: array
minItems: 1
items:
type: string
pattern: '[a-zA-Z]*'
x-nullable: false
field2:
type: array
minItems: 1
items:
type: string
pattern: '[a-zA-Z]*'
x-nullable: false
Previously the definitions for the two fields were what are now the item definitions. The modifications mostly addresses my needs, however, I would like to require that the two arrays field1
and field2
have the same length. Is there a way to do this? I can see how I might modify the generated file to enforce this requirement, but I would much prefer not to have to do this every time I want to regenerate that file.
答案1
得分: 1
我想要求field1
和field2
这两个数组具有相同的长度。有没有办法实现这个要求?
这个要求无法通过OpenAPI规范来表达。你只能在模式(schema)的description
中提及这个要求。
英文:
> I would like to require that the two arrays field1
and field2
have the same length. Is there a way to do this?
This cannot be expressed using OpenAPI Specification. The most you can do is mention this requirement in the schema description
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论