Forum Discussion

lkovac's avatar
lkovac
New Contributor
4 years ago
Solved

Swagger: default some object items as not specified/missing

In swagger I define JSON (i.e. object) as input request body for API. Some JSON items are mandatory, others are not, and some of those I want to default (or show example as) to not be specified in the default JSON at all. How can I achieve this?

InputJSON:
  type: object
  required:
    - item1
  properties:
    item1:
      type: string
    item2:
      type: string
    item3:
      type: array
      items:
        type: string

Code above shows example as:

{
  "item1": "string",
  "item2": "string",
  "item3": [
    "string"
  ]
}

But I want it to be:

{
  "item1": "string"
}

Thank you.

  • Hi lkovac,

    To limit the properties included in the auto-generated examples, you'll need to provide an object-level example that includes just the needed properties:

    InputJSON:
      type: object
      required:
        - item1
      properties:
        ...
      example:   # <------
        item1: some_value

     

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi lkovac,

    To limit the properties included in the auto-generated examples, you'll need to provide an object-level example that includes just the needed properties:

    InputJSON:
      type: object
      required:
        - item1
      properties:
        ...
      example:   # <------
        item1: some_value