Home > OS >  Is there a way to require two array properties on an object to have the same length?
Is there a way to require two array properties on an object to have the same length?

Time:05-28

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.

CodePudding user response:

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.

  • Related