How to add default values in request body of swagger docs while using compojure-api

422 views Asked by At

Suppose you have schema like below

(s/defschema House
  {:bedroom s/Int
   :bathroom s/Int 
   :parking s/Int
})

The dynamic generation of swagger docs will assign a default value of 0. How do I assign default value for bedroom, bathroom, and parking for swagger docs ?

1

There are 1 answers

0
Abhishek Jaiswal On

We can achieve this using ring.swagger.json-schema. We can modify our schema using json-schema

(s/defschema House
  {:bedroom (ring.swagger.json-schema/field s/Int {:example 3})
   :bathroom (ring.swagger.json-schema/field s/Int {:example 2})
   :parking (ring.swagger.json-schema/field s/Int {:example 1})
})