Forum Discussion

snehakarnam's avatar
snehakarnam
New Member
4 years ago

How to mark additional properties as required field in open api 3

Hi ,

 

I have a reference schema which has additional properties properties defined as fallows,

testDto:
type: object
additionalProperties:
type: string
example:
name: Note
Threads: 5

how can i mark additionalProperties as a required field in openapi 3?

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    If you mean that the object must have at least N properties, use minProperties:

    testDto:
      type: object
      additionalProperties:
        type: string
      minProperties: 1    # <----------
      example:
        name: Note
        Threads: '5'

     

     

    The "required" list is only used to require specific named properties. For example, the following means that the object must have properties named "name" and "Threads" with any values and may have arbitrary extra properties.

    testDto:
      type: object
      required:
        - name
        - Threads
      additionalProperties:
        type: string

     This is equivalent to:

    testDto:
      type: object
      required:
        - name
        - Threads
      properties:
        name: {}     # any type
        Threads: {}  # any type
      additionalProperties:
        type: string