swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

How to display default value 0 on swagger-ui

Open zon999 opened this issue 11 years ago • 5 comments

Hi all, My result on swagger is:

{
  "name": "string",
  "wareHouseID": "Integer",
  "company": "string",
  "fullname": "string",
  "address": "string",
  "parentID": "Integer"
}

but I need "wareHouseID": 0, "parentID": 0. My question: How to set default values 0. My code:

    private int wareHouseID;
    private int parentID;
    private String name;
    private String fullname;
    private String company;
    private String address;

    public Warehouse() {
    }

    @ApiModelProperty(position = 1,required = true)
    public int getWareHouseID() {
        return wareHouseID;
    }

    public void setWareHouseID(int wareHouseID) {
        this.wareHouseID = wareHouseID;
    }

    @ApiModelProperty(position = 2,required = true)
    public int getParentID() {
        return parentID;
    }

Thanks all.

zon999 avatar Oct 08 '15 06:10 zon999

Hi @zonorion. I assume you're referring to the model view in swagger-ui. The view is split into two - the Model which gives you a similar output as you've pasted here, and the Model Schema. The Model simply shows the fields with their types, the default value plays no part in that. It's the Model Schema view that would show you the default value, should you set it. If you don't set those, they would default to 0 anyways.

webron avatar Oct 09 '15 01:10 webron

Maybe i used old swagger version? I used wornik not io :)

zon999 avatar Oct 09 '15 04:10 zon999

It is an old version, but that shouldn't affect what you see in the ui. Make sure you use the latest ui as well.

webron avatar Oct 09 '15 04:10 webron

Hi @webron, i use io.swagger but swager-ui result Can't read swagger JSON from http://localhost:8080/sunrise/api/api-docs Tell me how to fix it? Thanks

zon999 avatar Oct 09 '15 04:10 zon999

Tks @webron 4 support, i solve my problem

zon999 avatar Oct 09 '15 09:10 zon999