Forum Discussion
- ponelatStaff
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/
- gajendrabishtNew 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"
}
}
- ponelatStaff
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).
Related Content
Recent Discussions
- 5 days ago