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

Originally posted by snehakarnam on August 10, 2021

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?

Originally posted by HKosova on August 11, 2021

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