cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger: default some object items as not specified/missing

SOLVED
lkovac
Occasional Visitor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
HKosova
Moderator

Re: Swagger: default some object items as not specified/missing

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

 


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: Swagger: default some object items as not specified/missing

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

 


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