Forum Discussion

raghug's avatar
raghug
New Contributor
4 years ago

Repeatable request fields with different values

I haven api request with below dynamic fields with different values:   { "fieldName": "field1", "fieldType": "string", "fieldValue": "12345677" }, { "fieldName": "field2", "fieldType": "stri...
  • HKosova's avatar
    4 years ago

    Hi raghug,

     

    This payload is an array of objects. It can be defined as follows (assuming you're using OpenAPI 3.0)

    openapi: 3.0.0
    ...
    
    paths:
      /anything:
        post:
          requestBody:
            content:
              application/json:
                schema:
                  type: array   # <----------
                  items:
                    $ref: '#/components/schemas/Field'
                  example:      # <--- Optional array-level example
                    - fieldName: field1
                      fieldType: string
                      fieldValue: '12345677'
                    - fieldName: field2
                      fieldType: string
                      fieldValue: '12345677'
          responses:
            '200':
              description: OK
    
    components:
      schemas:
        Field:          # <----- Objects inside the array
          type: object
          properties:
            fieldName:
              type: string
              example: field1
            fieldType:
              type: string
              example: string
            fieldValue:
              type: string
              example: '12345677'