Ask a Question

Edit Field Default Data type

gajendrabisht
New Contributor

Edit Field Default Data type

I want to show the default value of field "id" from 0 to "number" in default example on swagger UI. How can i do that?

 

gajendrabisht_1-1678718134444.png

 

 

3 REPLIES 3
ponelat
Staff

The short answer is to add `default: 42` (or whatever number you'd like) in the same place that `id` is defined.

Eg:

id:
  type: number
  description: A simple ID
  example: 42

For more details on examples, see: https://swagger.io/docs/specification/adding-examples/

gajendrabisht
New Contributor

I want to show the value of field "id" to be "number" same as displayed for field "name" : "string" in default example on swagger UI. How can i do that?

Desired Output: 
{

 "id" : "number",

 "category": {

   "id" : "number",

   "name" : "string"

 }

}

 

gajendrabisht_0-1678776608801.png

 

 

That would make the example invalid since "number" isn't actually a number.

Some tools will attempt to validate that, although it is possible (but not advised) to work around that.

To workaround, use `default: 'number'` (eg: https://app.swaggerhub.com/apis/SwaggerPMTests/example-with-arbitrary-obj/1.0.0#/Example) . But again, this is not advised.

 

An alternative is to add more information about the field in `description` (see above example as well for that).

 

cancel
Showing results for 
Search instead for 
Did you mean: