cancel
Showing results for 
Search instead for 
Did you mean: 

Repeatable request fields with different values

SOLVED
raghug
New Contributor

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": "string",
"fieldValue": "12345677"
},
{
"fieldName": "field3",
"fieldType": "string",
"fieldValue": "12345677"
},

 

How can i define in swagger specification.

1 ACCEPTED SOLUTION

Accepted Solutions
HKosova
Moderator

Re: Repeatable request fields with different values

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'

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

1 REPLY 1
HKosova
Moderator

Re: Repeatable request fields with different values

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'

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors